Opened 12 years ago
Closed 12 years ago
#21525 closed defect (bug) (duplicate)
wp_list_pages: current page css fails with custom post types
Reported by: | martin.czerwi | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 3.4.1 |
Component: | Posts, Post Types | Keywords: | |
Focuses: | Cc: |
Description
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();
As an addition, when modifying the core file wp-includes/post-template.php with a check like 'is_post_type_hierarchical', everything worked as expected. My final code looks like this:
Maybe it's even possible to leave out is_page() in the statement. I didn't try that.