Getting WordPress Subpages

Having just finished a new WordPress theme, I thought it would be useful to share this bit of code that came in very useful for listing subpages on a parent page. Although it is possible to use a sidebar widget, I wanted to have the subpages listed on the page itself.

<?php $parent = $post->ID; ?>

<?php query_posts(‘posts_per_page=15&post_type=page&post_parent=’.$parent);

while (have_posts()) : the_post(); ?>

<div>
<a href=”<?php the_permalink(); ?>” title=”<?php the_title_attribute(); ?>”>

<h4 id=”subtext”><?php the_title(); ?></h4></a>

<p> <?php the_excerpt(); ?> </p>

</div>

<?php endwhile; ?>

 

This creates a new Loop which gets all the subpages of the current page, displaying the title and excerpt of the subpage.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>