WordPress and child page listing

Sometimes I want a listing of the child pages to be embedded in the text of a page. This could be done manually but then maintenance of the site is a nightmare (unless it is a really static site!)

So adding the following code into the relevant page template for the WordPress site works a treat.

 <?php
  $children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0');
  if ($children) { ?>
  <ul>
  <?php echo $children; ?>
  </ul>
  <?php } ?>

While it is not a rule, this related page listing is probably going to appear underneath any of the page text content, so look for the following in the page template and place the child page code below this line.

<?php the_content(); ?>

One reply

  1. […] ColorWay theme By InkThemes.com and while I like the theme it was annoying me that when I used the wp_list_pages function to get a list of child pages (which I logged earlier this year), it kept adding the Home page to the list as if it were a child […]

Leave a Reply to Tonys Tech Blog» Blog Archive » Wordpress wp_list_pages includes Home link for no reason Cancel reply

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