codex提供了一种显示子页面和父页面的方式,以用作子菜单。但是,即使父页面没有子页面,此代码也会在列表中显示父页面。如何修改此代码,使其仅在父级具有页面时显示?
功能。php
if(!function_exists(\'get_post_top_ancestor_id\')){
/**
* Gets the id of the topmost ancestor of the current page. Returns the current
* page\'s id if there is no parent.
*
* @uses object $post
* @return int
*/
function get_post_top_ancestor_id(){
global $post;
if($post->post_parent){
$ancestors = array_reverse(get_post_ancestors($post->ID));
return $ancestors[0];
}
return $post->ID;
}}
称之为:<?php wp_list_pages( array(\'title_li\'=>\'\',\'include\'=>get_post_top_ancestor_id()) ); ?>
<?php wp_list_pages( array(\'title_li\'=>\'\',\'depth\'=>1,\'child_of\'=>get_post_top_ancestor_id()) ); ?>