您可以这样做:
if ( ! $post->post_parent ) {
$pages = get_pages( \'child_of=\' . $post->ID );
$pages = $pages ? wp_list_pluck( $pages, \'ID\' ) : \'\';
$includes = $post->ID . ( $pages ? \',\' . implode( \',\', $pages ) : \'\' );
$children = wp_list_pages( \'title_li=&include=\' . $includes . \'&echo=0\' );
} else {
$pages = get_post_ancestors( $post );
$includes = $post->ID . \',\' . implode( \',\', $pages );
$children = wp_list_pages( \'title_li=&include=\' . $includes . \'&echo=0\' );
}
echo $children ? "<ul>$children</ul>" : \'\';
一、 e.使用
include
参数
对于顶级页面(post_parent
是0
), $children = wp_list_pages( \'title_li=&child_of=\' . $post->ID . \'&echo=0\' );
也可以,但不包括父标记(LI
) 除非手动添加它。我更喜欢有标记/LI
生成人wp_list_pages()
.