Genesis: Parent Page Templates

The template below displays child posts below any page content of the parent post with featured image thumbnails. Images are linked to child page. If there is an image before any page content on the child page, it will not display in order to avoid breaking the layout on posts with large images.

To display the images on the right side, change the class on this line (~ line 17):

genesis_image( array( 'format' => 'html', 'size' => genesis_get_option( 'image_size' ), 'attr' => array( 'class' => 'alignleft post-image' ) ) );

from

'class' => 'alignleft post-image'

to

'class' => 'alignright post-image'

Parent Page Template:

<?php // Template Name: Parent-Image-Left

add_action('genesis_after_loop', 'bd_child_pages');
function bd_child_pages(){
		global $post;
?>

<div id="child-pages">

	<?php query_posts( 'post_type=page&post_parent='.$post->ID.'&orderby=menu_order&order=ASC' ); ?>
	<?php if( have_posts() ) : while ( have_posts() ) : the_post(); ?>
	
		<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
		
<?php
	echo '<a href="' . get_permalink($post->ID) . '" >';
	    genesis_image( array( 'format' => 'html', 'size' => genesis_get_option( 'image_size' ), 'attr' => array( 'class' => 'alignleft post-image' ) ) );
	echo '</a>';
		
	$content = apply_filters( 'the_content', get_the_content() );
		
	preg_match('#<p[^>]*>(.*)</p>#isU', $content, $matches);
	$content = preg_replace('/<img[^>]+\>/i', '', $matches[0]);
		
	echo $content;
		
	$count = post_word_count();
	if( sizeof( explode( " ", $content) ) < $count ) { ?>
	<div class="readmore">
		<a href="<?php the_permalink(); ?>">Read more &hellip;</a>
	</div>
	<?php	} ?>
				
<div class="clear"></div>
<?php endwhile; endif; ?>
</div><!--end child-pages-->

<?php }

genesis();

functions.php:

// Post word count
function post_word_count() {
    ob_start();
    the_content();
    $wcount= ob_get_clean();
    return sizeof(explode(" ", $wcount) );
    ob_end_clean();
}

Changelog
2/23/2011: Added links to featured images and ob_end_clean() to word count function.

Leave a Comment