事实证明,在Wordpress forums is_tree()
function is_tree($pid) { // $pid = The ID of the page we\'re looking for pages underneath
global $post; // load details about this page
$anc = get_post_ancestors( $post->ID );
foreach($anc as $ancestor) {
if(is_page() && $ancestor == $pid) {
return true;
}
}
if(is_page()&&(is_page($pid)))
return true; // we\'re at the page or at a sub page
else
return false; // we\'re elsewhere
};
要在模板中使用它,只需给它一个要检查当前页面的ID,如果当前页面是子代,它将返回true。
<?php if(is_tree(12)){echo \'foobar\';} ?>