Support » Plugins and Hacks » List Child Pages with thumbnails – 2.9

List Child Pages with thumbnails – 2.9

  • Hi,

    I want to create a page template that I can use for Parent pages to list all of the child pages with title, excerpt (auto generated if possible), and post thumbnail. I see lots of ways to do this in previous versions of WP, but not with 2.9 – and with the changes in thumbnails that 2.9 brings – I don’t know how to go about doing this.



Viewing 4 replies - 1 through 4 (of 4 total)
  • i’m trying to do this as well, found a solution?



    Forum Moderator

    Completely untested but what about:

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <div <?php post_class(); ?>>
    $args = array(
    	'post_parent' => $post->ID,
    	'post_type' => 'page',
    	''post_status' => 'publish'
    $children = & get_children($args);
    if ( empty($children) ) {
    	// no sub-pages here
    } else {
    	foreach ( $children as $post) {
    		<h2><a href="<?php the_permalink(); ?>" id="post-<?php the_ID(); ?>"><?php the_title(); ?></a></h2>
    		<?php if( has_post_thumbnail() ) the_post_thumbnail(); ?>
    		<?php the_excerpt();

    I needed the same thing. But I couldn’t get the code above to work for me so I played and read and came up with:

          $args = array(
    	'post_parent' => $post->ID,
    	'post_type' => 'page',
    	'post_status' => 'publish'
    	 $postslist = get_posts($args);
         foreach ($postslist as $post) :
             <div class="portfolio_box">
                 <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                 <div class="indexexcerpt">
                 <?php the_excerpt(); ?> <div style="text-align:right">[ <a href="<?php the_permalink(); ?>">Read more</a> ]</div>
                 <div class="divider"> </div>
         <?php endforeach; ?>

    I use the plugin Advanced Excerpt to manage how the excerpt work. This is a genius plugin! It will include the image from the post (presuming that it is the first) and let you decide how many words to show, and a lot more. If that doesn’t suit I found a function to grab the first image from a post and display that.

    For laymen, don’t forget to consult Codex on get_posts to generate your desired output

    The array should include number of posts otherwise it will default to 5. You can override the limit altogether with -1.

    'numberposts' => 10,
    'numberposts' => -1,

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘List Child Pages with thumbnails – 2.9’ is closed to new replies.
Skip to toolbar