试试这个,这是最基本的实现。可以更有效地pre_get_posts, 并将查询从“顶级页面”更改为对其子级的查询。但这可能会破坏一些东西,尤其可能需要您更改所使用的模板。
<?php if ( have_posts() ) : while ( have_posts() ) : the_post();  ?>
    <header class="entry-header">
        <h1 class="entry-title"><?php the_title(); ?></h1>
    </header><!-- .entry-header -->
    <?php   //If top level, find children
        if($post->post_parent == 0):
            $children = new WP_Query(array(
                \'post_type\'=>\'page\',
                \'post_parent\'=>$post->ID
            ));
            if($children->have_posts()): ?>
                <ul>
                <?php while ( $children->have_posts() ) : $children->the_post(); ?>
                    <li> <?php the_title();?> </li>
                <?php endwhile; ?>
                </ul>
            <?php else: ?>
                <?php echo \'No children\';?>
            <?php endif; ?>
            <?php wp_reset_postdata(); ?>
        <?php else://Not top level, display normal post ?>
            <?php the_content(); ?>
        <?php endif;?>
    <?php endwhile; // end of the loop. ?>
<?php endif; ?>