WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm wondering how to write a list of sub-pages of actually visited page.

So I have 2 pages and 3 sub-pages for each:

Colors [page]
- Red [child of Colors - subpage]
- Blue [child of Colors - subpage]
- Green [child of Colors - subpage]

Numbers [page]
- One [child of Numbers - subpage]
- Two [child of Numbers - subpage]
- Three [child of Numbers - subpage]

And when user visits "Colors" page then my code outputs Red/Blue/Green and if he does vist Numbers it shows One/Two/Three.

I'm sure wp_list_pages will do the thing easy, but I'm not sure about parameters.

share|improve this question
up vote 2 down vote accepted

easy just pass it the $id off which to get the children

  global $id;

of if you want in the loop then

share|improve this answer
it doesn't work for me. The first code shows nothing. The second shows the list of all pages & sub-pages. Are you sure this should work inside of a widget? BTW when I type "echo $id" it echoes ID of the SIDEBAR. – Wordpressor Mar 4 '11 at 23:18

Look at the code of my Shortcode Plugin. The parameter child_of takes $GLOBALS['post']->ID as an argument. The other arguments are documented in the Codex page.

If you use the shortcode you can add a parameter in_comments and suppress any visible output if there are no child pages. Example:

<!--[subpages in_comments=1]-->

Useful if you move or delete pages.

share|improve this answer

Here's a snippet from a page template I use to list subpages:

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<h1><?php the_title(); ?></h1>
<?php the_content(); ?>
    $children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0');
    if ($children) { ?>
        <?php echo $children; ?>
<?php } ?>
<?php endwhile; endif; ?>
share|improve this answer
your code also shows list of all pages and sub-pages. – Wordpressor Mar 4 '11 at 23:21

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.