我在另一个线程中找到了这个片段,它主要完成了我需要的任务,但我在用标签包装输出的各个页面时遇到了问题。我能补充的似乎只有换行符。我对php没有太多经验,所以很遗憾,我无法根据自己的需要定制它。最后,我只需要显示第一级和第二级页面标题,它们需要包装在单独的h2中。提前感谢。
//This is the loop that pulls banner titles
function print_page_parents($reverse = true){
global $post;
//create array of pages (i.e. current, parent, grandparent)
$page = array($post->ID);
$page_ancestors = get_ancestors($post->ID, \'page\');
$pages = array_merge($page, $page_ancestors);
if($reverse) {
//reverse array (i.e. grandparent, parent, current)
$pages = array_reverse($pages);
}
for($i=0; $i<count($pages); $i++) {
$ban_titles.= get_the_title($pages[$i]);
if($i != count($pages) - 1){
$ban_titles.= " <br /> ";
}
}
echo $ban_titles;
}