使用这样的东西怎么样(前提是您有办法获取正在检查子页面的页面ID):
$children = get_pages( array( \'child_of\' => $post->ID ) );
但是,如果您只想获得直系后代,请参阅m0r7if3r,否则这也适用:
$children = get_pages( array( \'child_of\' => $post->ID, \'parent\' => 0 ) );
然后使用
count($children)
使用这样的if语句:
if( count( $children ) > 0 ) {
// has children (and grandchildren if not using the \'parent\' param)
} else {
// does not have children
}