wp_list_pages: current page css fails with custom post types
|Reported by:||martin.czerwi||Owned by:|
|Component:||Posts, Post Types||Keywords:|
In a customer project I used a custom post type 'products' for content-pages. 'products' is registered with 'public' => true and 'hierarchical' => true.
For a sub navigation I'm using wp_list_pages() to list all sibling 'products'. Usually you get css-classes in the output, to highlight the current pages, or ancestors and so on. This works fine, when using regular pages, but when using my custom post type, the current page isn't highlighted, the class is missing.
I looked at the code and after testing a bit I discovered walk_page_tree() receives '0' as the $current_page parameter. That's the reason why no css-classes for the current page are output.
In wp-includes/post-template.php in wp_list_pages() (http://core.trac.wordpress.org/browser/trunk/wp-includes/post-template.php#L828) the $current_page parameter for walk_page_tree() is determined. When you have a custom post-type the if statement fails:
if ( is_page() || is_attachment() || $wp_query->is_posts_page ) $current_page = $wp_query->get_queried_object_id();