WordPress.org

Ready to get started?Download WordPress

Forums

List Child Pages with thumbnails - 2.9 (5 posts)

  1. jasonday
    Member
    Posted 4 years ago #

    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.

    Help?

    Thanks!

  2. dposterboy
    Member
    Posted 3 years ago #

    i'm trying to do this as well, found a solution?

  3. esmi
    Theme Diva & Forum Moderator
    Posted 3 years ago #

    Completely untested but what about:

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <div <?php post_class(); ?>>
    <?php
    $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) {
    		setup_postdata($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();
    	}
    }?>
    </div>
  4. nathan12343
    Member
    Posted 3 years ago #

    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:

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

  5. twincitian
    Member
    Posted 3 years ago #

    For laymen, don't forget to consult Codex on get_posts to generate your desired output
    http://codex.wordpress.org/Template_Tags/get_posts

    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,

Topic Closed

This topic has been closed to new replies.

About this Topic