The wp_list_pages() function displays a list of WordPress pages as links and is often used to display navigation menus. When it prints the list of links, it adds a CSS class current_page_item to the list item tag of the current page. This allows custom styling to be applied to the link e.g. to highlight a link to indicate the page that the visitor is on.
The limitation with this is that it only works if you are viewing a page or an attachment, or are on the posts page (as set in Settings > Reading).
I was working on an archive page for a custom taxonomy and wanted to have the current_page_item CSS class added to the list item of a particular link of my choice. After poking around a bit in the wp_list_pages() code listing, I discovered it’s possible to hack the $wp_query object to make wp_list_pages() do what I wanted it to.
Here’s how:
// Get the ID of the link you want highlighted. Either:
// - hardcode it (as below)
// - or query the database to get it
$the_id = "1";
// Make a copy of the $wp_query object
$temp_query = clone $wp_query;
// Trick WordPress into thinking we're on a page with ID $the_id
$wp_query->is_page = 1;
$wp_query->queried_object_id = $the_id;
// Display pages
wp_list_pages("title_li=");
// Reset $wp_query
$wp_query = clone $temp_query;
Notes:
$wp_query->is_pageneeds to be set to1(true) becausewp_list_pages()does not set a current page unlessis_page()oris_attachment()or$wp_query->is_posts_pagereturns true.- If you only want this code to run when you are on certain page you can wrap it in an
ifstatement that checks a WordPress conditional tag. In my case I only wanted to run this code when a taxonomy archive was being displayed so I usedis_tax(). - See http://www.jenst.se/2008/03/17/wordpress-get-id-by-post-or-page-name/ on how to query the database by post/page name to get an ID.

Short. Sweet. Powerful.. brilliant!
Thanks
Michael.
works great. thanks.
You’ve just avoided a nervious breakdown! It just works great. Thank you very much for your time and generosity.
very helpful, thank you
Oh how awesome — thanks for posting this! Now for the beer I owe you: what’s your PayPal donation address?
Thanks, it works just fine.
Thanks! it made my day!
To make this work for an archive page, you also need a $wp_query->queried_object = ”; under line 10.
Your idea is brilliant, but i don’t know why i can’t implement it.
but i found another way with simple code.
just call wp_list_pages() before call query or else
best case is after get_header();
Thanks!
sorry, just left important note.
call wp_list_pages using echo=0, and save to variable.
$somevar = wp_list_pages(‘title_li&echo=0′);
Thanks a lot for that Post!
Awesome mate, thanks for sharing this. Just what I was looking for and saved me some time!