Show Sub-Pages on Parent in WordPress

This is a bit of code that will can be used as a page template in WordPress. It first displays the parent page, then enters a loop to display all of the child pages. This is really useful for organization in large WordPress-as-a-CMS sites.

Just make a new PHP file in your theme directory and paste in this code:

<?php
/*
Template Name: Section Listing Page
*/
?>

<?php get_header(); ?>

<?php if(have_posts()) : while(have_posts()) : the_post(); ?>
<div class="post" id="<?php the_ID(); ?>">
<h2><?php the_title(); ?></h2><?php edit_post_link('Edit this Page','<p class="meta">','</p>'); ?>
<div class="entry">
<?php the_content(); ?>
</div>
</div> <!-- end "post" -->
<?php $pageid = get_the_ID(); ?>
<?php endwhile; endif; ?>

<?php $subpages = new WP_Query("post_parent=$pageid&post_type='page'&orderby=title&order=ASC");
if($subpages->have_posts()) : while($subpages->have_posts()) : $subpages->the_post(); ?>
<div class="post">
<?php echo '<h3><a name="' . the_slug() . '" href="' . the_permalink() . '">' . get_the_title() . '</a></h3>'; ?>
<?php edit_post_link('Edit this Page','<p class="meta">','</p>'); ?>
<div class="entry">
<?php the_content(); ?>
</div>
</div>
<?php endwhile; endif; ?>

<?php get_sidebar(); ?>

<?php get_footer(); ?>

Then all you need to do is select your file under “Page Template” on the edit screen.