Make WordPress Core

Opened 7 years ago

Last modified 4 years ago

#17590 closed defect (bug)

wp_list_pages() not setting "current_page_item" classes on custom post types — at Version 2

Reported by: tobiasn Owned by:
Milestone: 3.9 Priority: normal
Severity: normal Version: 3.1
Component: Posts, Post Types Keywords: has-patch commit
Focuses: Cc:

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. )

Change History (3)

7 years ago

wp_list_pages() css patch for custom post types

#1 @husobj
7 years 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 );

#2 @SergeyBiryukov
7 years ago

  • Description modified (diff)

Corrected markup.

Note: See TracTickets for help on using tickets.