我已经想出了自己的解决方案,但我不相信这是最好的。
$parents = array( $post->ID );
if( 0 != $post->post_parent )
{
$parents = array_merge( $parents, get_post_ancestors( $post->ID ) );
}
$child_of = end( $parents );
$args = array
(
\'child_of\' => $child_of,
\'echo\' => 0,
\'title_li\' => \'\',
\'walker\' => new chg_Sub_Page_Navigation_Walker( $parents )
);
$pages = wp_list_pages( $args );
Walker:
class chg_Sub_Page_Navigation_Walker extends Walker_Page
{
var $parents = array();
function __construct( $parents )
{
$this->parents = $parents;
}
function start_el( &$output, $page, $depth, $args, $current_page )
{
if( in_array( $page->post_parent, $this->parents ) )
parent::start_el( &$output, $page, $depth, $args, $current_page );
}
function end_el( &$output, $page, $depth )
{
if( in_array( $page->post_parent, $this->parents ) )
parent::end_el( &$output, $page, $depth );
}
}