treehouse : what would you like to learn today?
Web Design Web Development iOS Development

How do I show a pages sub-pages in WordPress

  • As stated in the post's topic, i was wondering if someone knew how to list sub-pages of a page within the same page. For example, I would like a page named products to list a bunch of products by a certain company, and when more products are added as a sub-page of the products page, the list gets updated to reflect the change. I'm there's a single wp tag that would do this, so please forgive my stupidity for not knowing this.

    Many thanks in advance for your help.
  • The best place to start is always the codex http://codex.wordpress.org/Template_Tags/wp_list_pages#List_subpages_even_if_on_a_subpage

    This is what you are looking for
    <?php
    $children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0');
    if ($children) { ?>
    <ul>
    <?php echo $children; ?>
    </ul>
    <?php } ?>