此函数将执行此操作,它显示当前页面的子页面,但如果没有子页面,则显示父页面的子页面,并返回到父页面的链接。
/**
* @brief: Shows the subpages of the current page, or
* the adjacent sibling pages.
**/
function show_subpages(){
global $post;
$subpages = wp_list_pages( array(
\'echo\'=>0,
\'title_li\'=>\'\',
\'depth\'=>2,
\'child_of\'=> ( $post->post_parent == 0 ? $post->ID : $post->post_parent)
));
if ( !empty($subpages) ) {
if ( $post->post_parent != 0 ) {
echo \'<p class="parent-link"><em>\'. __(\'Back to\') .\' <a href="\'. get_permalink($post->post_parent) .\'">\'. get_the_title($post->post_parent) .\'</em></a><p>\';
}
echo \'<ul>\';
echo $subpages;
echo \'</ul>\';
} else {
echo \'no subpages\';
}
}
您可能需要将其置于主循环中