0

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.

2

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

  global $id;
  wp_list_pages("title_li=&child_of=$id");

of if you want in the loop then

 wp_list_pages("title_li=&child_of=$post->ID");
  • 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
0

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(); ?>
<?php
    $children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0');
    if ($children) { ?>
    <ul>
        <?php echo $children; ?>
    </ul>
<?php } ?>
<?php endwhile; endif; ?>
  • your code also shows list of all pages and sub-pages. – Wordpressor Mar 4 '11 at 23:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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