Opened 2 years ago
Last modified 7 months ago
#17590 new defect (bug)
wp_list_pages() not setting "current_page_item" classes on custom post types
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Future Release |
| Component: | Themes | Version: | 3.1 |
| Severity: | normal | Keywords: | has-patch |
| Cc: | ben@…, daveleeone |
Description (last modified by SergeyBiryukov)
wp_list_pages() don't set the correct css for a hierarchical custom post type.
To reproduce this bug do this:
<?php wp_list_pages("title_li=&post_type=custom_post_type_name"); ?>
and compare the html output to normal pages:
<?php wp_list_pages(); ?>
The problem seems to be this row in wp_list_pages():
if ( is_page() || is_attachment() || $wp_query->is_posts_page )
In the following patch i've changed it to
if ( is_page() || is_attachment() || $wp_query->is_posts_page || ($wp_query->query_vars['post_type'] != 'post' && is_single()) )
(If this is not the intended behavoir please let me know. )
Attachments (4)
Change History (18)
comment:1
follow-up:
↓ 3
husobj
— 23 months ago
- Cc ben@… added
As a temporary measure you can hook into to add selected classes like this:
function my_page_css_class( $css_class, $page ) {
global $post;
if ( $post->ID == $page->ID ) {
$css_class[] = 'current_page_item';
}
return $css_class;
}
add_filter( 'page_css_class', 'my_page_css_class', 10, 2 );
comment:3
in reply to:
↑ 1
tobiasn
— 22 months ago
Nice quickfix, however i would prefer pinpointing custom post types.
Replying to husobj:
As a temporary measure you can hook into to add selected classes like this:
function my_page_css_class( $css_class, $page ) { global $post; if ( $post->ID == $page->ID ) { $css_class[] = 'current_page_item'; } return $css_class; } add_filter( 'page_css_class', 'my_page_css_class', 10, 2 );
comment:4
depi
— 16 months ago
Thanks for the fix with the hook guys.
However I really wonder why it is still not fixed after 9 months.
comment:5
daveleeone
— 15 months ago
- Cc daveleeone added
- Type changed from defect (bug) to feature request
Thanks for the very useful hook, but how can I highlight the parent page? At the moment I use Jquery for this.
Any Ideas?
Thanks, Davelee
comment:6
daveleeone
— 15 months ago
- Type changed from feature request to defect (bug)
comment:7
tobiasn
— 15 months ago
Hi dave! I haven't noticed the parent page-thing, guess that's a bug in the Walker class. How do I recreate it?
comment:8
follow-up:
↓ 9
daveleeone
— 14 months ago
remove my comment and repost it in the support forum
http://wordpress.org/support/topic/current_page_item-hack-for-custom-post-typs?replies=2#post-2744994
comment:9
in reply to:
↑ 8
tobiasn
— 14 months ago
Hi Dave! This has nothing to do with the trac bug. Could you please remove the comment here and repost it in the support forum? I'll answer you there.
comment:10
thomas.mery
— 12 months ago
Hi,
I was wondering if this had been looked at ?
it seems like this would be quite useful now that CPT are used so often by the wp community
thanks
comment:11
SergeyBiryukov
— 10 months ago
Closed #21525 as a duplicate.
SergeyBiryukov
— 10 months ago
comment:12
SergeyBiryukov
— 10 months ago
- Milestone changed from Awaiting Review to 3.5
SergeyBiryukov
— 8 months ago
comment:13
SergeyBiryukov
— 8 months ago
17590.2.patch does a hierarchical check, as suggested during the bug scrub.
is_attachment() was added in [10947] (for #9472), so I've kept it.
comment:14
nacin
— 7 months ago
- Milestone changed from 3.5 to Future Release
get('post_type') could be an array.
wp_list_pages() css patch for custom post types