要在h2中包装您的标题,只需更改echo $ban_titles;
到echo \'<h2>\'. $ban_titles . \'</h2>\';
.
如果要将显示的标题数限制为2,请更改for($i=0; $i<count($pages); $i++)
到for($i=0; $i<2; $i++)
.
希望有帮助,PHP毕竟没有那么可怕:)
[编辑]
那怎么样?
//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);
}
$i = 0;
if(count($pages)==1) {
echo \'<h2>\'. get_the_title($pages[$i]) .\'</h2>\';
} else {
echo \'<h2>\'. get_the_title($pages[$i]) .\'</h2>\';
echo \'<h2>\'. get_the_title($pages[$i+1]) .\'</h2>\';
}
}