我在Wordpress中有一个父页面,并且使用以下代码显示有关父页面的每个子页面的信息。完善。我需要在页面的其他地方做的是显示子页面的计数,例如"此页面有 X 个子页面"。谁能帮我做到这一点?
<?php
$args = array(
'post_type' => 'property',
'posts_per_page' => -1,
'post_parent' => $post->ID,
'order' => 'ASC',
'orderby' => 'menu_order'
);
$parent = new WP_Query( $args );
if ( $parent->have_posts() ) :
?>
<?php while ( $parent->have_posts() ) : $parent->the_post(); ?>
//content goes here
<?php endwhile; ?>
<?php endif; wp_reset_query(); ?>
你可以
像这样使用
$pages = get_pages( array( 'child_of' => $post->ID, 'post_type' => 'property'));
$count = count($pages);