In `wp_list_pages()`, add the `current_page_item` class where applicable when used with a custom post type.
Adds a unit test. Props nacin. Fixes #17590. git-svn-id: https://develop.svn.wordpress.org/trunk@27755 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
8aeeaf976a
commit
09c4928cf7
|
@ -1009,8 +1009,15 @@ function wp_list_pages($args = '') {
|
||||||
$output .= '<li class="pagenav">' . $r['title_li'] . '<ul>';
|
$output .= '<li class="pagenav">' . $r['title_li'] . '<ul>';
|
||||||
|
|
||||||
global $wp_query;
|
global $wp_query;
|
||||||
if ( is_page() || is_attachment() || $wp_query->is_posts_page )
|
if ( is_page() || is_attachment() || $wp_query->is_posts_page ) {
|
||||||
$current_page = $wp_query->get_queried_object_id();
|
$current_page = get_queried_object_id();
|
||||||
|
} elseif ( is_singular() ) {
|
||||||
|
$queried_object = get_queried_object();
|
||||||
|
if ( is_post_type_hierarchical( $queried_object->post_type ) ) {
|
||||||
|
$current_page = $queried_object->ID;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$output .= walk_page_tree($pages, $r['depth'], $current_page, $r);
|
$output .= walk_page_tree($pages, $r['depth'], $current_page, $r);
|
||||||
|
|
||||||
if ( $r['title_li'] )
|
if ( $r['title_li'] )
|
||||||
|
|
|
@ -211,4 +211,29 @@ class Tests_Post_getPages extends WP_UnitTestCase {
|
||||||
|
|
||||||
$this->assertEqualSets( array( $page_1, $page_2, $page_4, $page_3 ), wp_list_pluck( $pages, 'ID' ) );
|
$this->assertEqualSets( array( $page_1, $page_2, $page_4, $page_3 ), wp_list_pluck( $pages, 'ID' ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function test_wp_list_pages_classes() {
|
||||||
|
$type = 'taco';
|
||||||
|
register_post_type( $type, array( 'hierarchical' => true, 'public' => true ) );
|
||||||
|
|
||||||
|
$posts = $this->factory->post->create_many( 2, array( 'post_type' => $type ) );
|
||||||
|
$post_id = reset( $posts );
|
||||||
|
|
||||||
|
$this->go_to( "/?p=$post_id&post_type=$type" );
|
||||||
|
|
||||||
|
$this->assertEquals( $post_id, get_queried_object_id() );
|
||||||
|
|
||||||
|
$output = wp_list_pages( array(
|
||||||
|
'echo' => false,
|
||||||
|
'title_li' => '',
|
||||||
|
'post_type' => $type
|
||||||
|
) );
|
||||||
|
|
||||||
|
$this->assertNotEmpty( $output );
|
||||||
|
$this->assertEquals( 2, substr_count( $output, 'class="page_item ' ) );
|
||||||
|
$this->assertContains( 'current_page_item', $output );
|
||||||
|
$this->assertEquals( 1, substr_count( $output, 'current_page_item' ) );
|
||||||
|
|
||||||
|
_unregister_post_type( $type );
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue