WordPress Show title and excerpt of child pages on Parent page

When you want to display all the child pages title and excerpt of current parent page then you can display by adding following code in your page template file

<?php
$child_pages = $wpdb->get_results("SELECT *	FROM $wpdb->posts WHERE post_parent = ".$post->ID."	AND post_type = 'page' ORDER BY menu_order", 'OBJECT');	?>
<?php if ( $child_pages ) : foreach ( $child_pages as $pageChild ) : setup_postdata( $pageChild ); ?>
<h2 class="subpagetitle"><a href="<?php echo  get_permalink($pageChild->ID); ?>" rel="bookmark" title="<?php echo $pageChild->post_title; ?>"><?php echo $pageChild->post_title; ?></a></h2>
/* And if you want to get the custom field values then you can get that by */
$your_custom_field = get_post_meta($pageChild->ID, 'your_custom_field', $single = true);
<?php the_excerpt();?>
<?php endforeach; endif;
?>

If you don’t want to display child pages on every page then you can use WordPress Conditional Tags.

20 Comments

  1. JuanjoNo Gravatar
    Mar 10, 2010

    How can I use de plugin? It’s activated and options ok… but it dón’t see what’s the code to insert in a post [/code]

    • snileshNo Gravatar
      Mar 11, 2010

      @Juanjo
      Sorry right now there are no short-codes available to insert the slideshow in the post page or widget area.
      If you want to display the slidee in your theme then you have to add this code.

      <?php include (ABSPATH . '/wp-content/plugins/content-slide/slideshow.php'); ?>
      

      in your theme .php files where you want to show that slider.

  2. sebastian yukeNo Gravatar
    Mar 30, 2010

    I have used News ticker. But my boss want to display a page that contain all the post from new ticker. Is it possible?

  3. BabarNo Gravatar
    Apr 06, 2010

    Hi

    First of all great plugin very decent style and different from others as well.

    I have placed on my website and its working fine but my top navigation’s dropdown not working with this plugin.. I’m using this plugin for page navigation WP-PageNavi.

    Is there anything can i do and it will fix ?

  4. BabarNo Gravatar
    Apr 06, 2010

    It has been solved. actually there was already called jquery in the header and this plugin calling it self another jquery file which is conflicting with each other. Just removed the plugin file and its working fine :)

  5. John CrumptonNo Gravatar
    May 03, 2010

    Thank you that’s really helped me out. I was struggling with http://wpguru.co.za/templates/page/display-title-excerpt-of-child-pages/ but this worked a treat!

  6. argroneNo Gravatar
    May 03, 2010

    I can activate the plug-in however, when I go to save the settings I am getting a 500 Internal Server error… any ideas?

  7. Michael CaputoNo Gravatar
    May 10, 2010

    Hey there, this worked great for me.

    Any chance you could share how we can access custom fields within the loop?

    • snileshNo Gravatar
      May 11, 2010

      @Michael Caputo
      Use

      $your_custom_field = get_post_meta($pageChild->ID, 'your_custom_field', $single = true);
      

      within the loop to get the custom field values.

  8. Michael CaputoNo Gravatar
    May 11, 2010

    Thanks for responding so quickly!

    I’ve got the custom fields working, now i’m trying to get the links to the sub pages working. the

    <?php echo $pageChild->guid; ?>

    doesn’t seem to want to link to the sub page.. Any help?

  9. Michael CaputoNo Gravatar
    May 12, 2010

    Got it

    echo $pageChild->guid;
  10. MarcoNo Gravatar
    May 12, 2010

    Where are the screenshots? I can’t see them..

  11. AnthonyNo Gravatar
    May 15, 2010

    I setup the code on my page template file. It works, but the thumbnail is of the parent page and not of the child pages. How can I display the child page thumbnails next to the child page excerpt.

  12. DrewNo Gravatar
    May 25, 2010

    Hey, great snippet! Is there a way that this line `$pageChild->guid` can be changed to respect the Permalink settings. Currently it gives out the raw link, not a pretty one. Thanks!

    • snileshNo Gravatar
      May 25, 2010

      Yes Replace

      <?php echo $pageChild->guid; ?>

      with

      <?php echo get_permalink($pageChild->ID); ?>

      I edited that in post now….

  13. Carey BestNo Gravatar
    Jun 17, 2010

    Awesome trick, but is there a way we can get the child page’s image? I’ve been trying with , but all I get is a repeated display of my current page’s image.

    Thanks again.

  14. Fábio ZCNo Gravatar
    Jun 23, 2010

    Hi!
    Thx for this code.
    But.. i got one problem.. when have more than 1 level of sub-pages, the excerpt that show is of the first child page. Ex:
    - Top page
    - – Child 1
    - – - Child Child 1
    - – - – Child Child Child 1

    At the second level, instead shows the excerpt of “Child Child Child 1″, shows the “Child 1″ Excerpt.

    Got it? Anyway to solve this problem?

    Thanks

  15. Fábio ZCNo Gravatar
    Jun 24, 2010

    finally everything is ok..
    i changed

    by
    post_excerpt;?>

  16. GuyNo Gravatar
    Jul 16, 2010

    thanks for posting this, just what I needed! :)

    just have to work out how to show the image in miniature using custom fields now.

  17. DaveTNo Gravatar
    Jul 30, 2010

    Fantastic script. Ty. After way to many hours yours works. Can you show a beginner how to fine tune the code to add the pic and maybe create a link from the title to the full page? Again thank you for helping make better blogs for all


Trackbacks and Pings

Leave a Reply