Showing list of subpages on pages (8 posts)

  1. trejder
    Posted 6 years ago #

    Hi there,

    I'm constructing a WP-based blog that contains many information on pages instaead of post, layed in a nice layout of pages and subpages. Is it possible (and how to achieve it - by modifying theme PHP code or using some function) to list all subpages belonging to current page when this page is displayed?

    For example, I have:

    - Info
    -- About
    -- Contact
    - My works
    -- Photo
    -- WWW

    Info and My works are empty now as they are only placeholders for subpages. I would like to list About and Contact when user select Info and Photo and WWW when displays My works.

    Of course I can add each new subpage manually on its ancestor page. But in fact I forgot about it most of the time and think that this could be somehow automated?


  2. MichaelH
    Posted 6 years ago #

    One possibility is the plugin http://wordpress.org/extend/plugins/template-tag-shortcodes/ along with the shortcode:


    Or you would need to use the template tag, wp_list_pages() in a Page template.

    In either case you will use the child_of=x argument.

  3. scotchegg78
    Posted 6 years ago #

    uck plugins for this :)

    Get your hands dirty ...

    use this code in your theme file...

    <div id="submenu">
    $children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0");
    $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
    if ($children) { ?>
    <?php echo $children; ?>
    <?php } ?>
  4. trejder
    Posted 6 years ago #


    The solution you've provided works perfectly except for the fact that it only displays subpages titles as link to them. How to modify above code to have actually displayed title and lead (part of each page before pressing "Insert read more tag) - text that in post is displayed before "Read more" link?

  5. MichaelH
    Posted 6 years ago #

    Look at using Function_Reference/get_pages <---there's examples in that article.

  6. Ovidiu
    Posted 6 years ago #


    I'd love to use that plugin, but this short code: [wp_list_pages] lists all pages, not only the subpages of the current page...

  7. atomik
    Posted 6 years ago #

    @trejder: Hallo, did you find a solution at the end? I'm struggling with the same issue...

  8. keesiemeijer
    Posted 6 years ago #

    put this function in your functions.php:

    function my_page_exerpts($parentID = false, $limit) {
       if($parentID) {
       $pages = get_pages('child_of='.$parentID);
       $limit = ($limit == '') ? 40 : $limit;
       $html = '';
         if(!empty($pages)) {
           foreach($pages as $page) {
           $mycontent = $page->post_content;
           $mycontent = strip_shortcodes($mycontent);
           $mycontent = str_replace(']]>', ']]>', $mycontent);
           $mycontent = strip_tags($mycontent);
           $contentTemp = explode(' ', $mycontent);
             if (count($contentTemp) > $limit) {
               $mycontent = implode(' ', array_slice($contentTemp, 0, $limit));
           $html .= '<h2><a href="' .get_page_link($page->ID) . '" title="';
           $html .=  $page->post_title . '">' .$page->post_title . '</a></h2>';
           $html .= '<p>' . $mycontent . '</p>';
           $html .= '<a href="' . get_page_link($page->ID) . '" ';
           $html .= 'title="read more about: ' . $page->post_title . '" >';
           $html .= 'Read More</a>';
       return $html;

    And call this function in your page.php template file:

      if($post->post_parent == 0){
      echo my_page_exerpts($post->ID, 20);

    The second value (20) is how long your excerpt is going to be. In the example it is 20 words long

Topic Closed

This topic has been closed to new replies.

About this Topic