我试图在侧边栏的一个页面中列出家长。我可以获取父页ID。我可以使用print\\r函数将其打印出来,但无论我尝试什么,都无法获取要显示的get\\u permalink和get\\u title。
<?php
global $wp_query;
if(!$wp_query->post->post_parent){ //no parent
$children = wp_list_pages("title_li=&depth=1&child_of=".$wp_query->post->ID."&echo=0"); // will display the subpages of this top level page
}else{ // diplays only the subpages of parent level
if($wp_query->post->ancestors){
$ancestors = end($wp_query->post->ancestors);
$ancestorsID = get_post_ancestors($wp_query->post->ID);
$children = wp_list_pages("title_li=&child_of=".$ancestors."&echo=0");}
}
if ($children) {
echo \'<ul>\';
if($wp_query->post->ancestors){
echo \'<li>\'; print_r($ancestorsID[0]); get_permalink($ancestorsID[0]); get_the_title($ancestorsID[0]); echo \'</li>\'; }
else {echo \'<li><a href="\';the_permalink(); echo \'" title="Permalink to \';the_title(); echo \'" rel="bookmark">\'; the_title(); echo \'</a></li>\';}
echo $children;
echo \'</ul>\';
} ?>