超级基本示例,获取父页面的标题和内容,然后获取每个子页面的标题和内容。这不仅仅是循环,而是整个页面模板。
<?php include_once( \'header.php\' ); ?>
<?php
$my_wp_query = new WP_Query();
$all_wp_pages = $my_wp_query->query(array(\'post_type\' => \'page\'));
?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div class="post-content">
<?php echo \'<h2>\'.$post->post_title.\'</h2>\'; ?>
<?php the_content(); ?>
</div><!-- post content -->
<?php
$children = get_page_children( $post->ID, $all_wp_pages );
if($children != null){
foreach($children as $child){ ?>
<h2><?php echo $child->post_title; ?></h2>
<div class="post-content">
<?php echo $child->post_content; ?>
</div>
<?php
}
}
?>
<?php endwhile; else: ?>
<p>Sorry, no posts matched your criteria.</p>
<?php endif; ?>
<?php include_once( \'footer.php\' ); ?>