Viewing 1 replies (of 1 total)
  • This will be so much easier once themes start enabling the new the_post_image function. In the meantime, try adding:

    function my_post_image( $post, $thumb_width, $thumb_height ) {
    	$thumb_width = get_option('thumbnail_size_w');
    	$thumb_height = get_option('thumbnail_size_h');
    	$first_image = array();
    	$args = array(
    		'post_type' => 'attachment',
    		'post_mime_type' => 'image',
    		'numberposts' => 1,
    		'post_status' => null,
    		'orderby' => ID,
    		'post_parent' => $post->ID
    		);
    	$attachments = get_posts($args);
    	if ($attachments) {
    		foreach ($attachments as $attachment) {
    			$first_image = wp_get_attachment_image_src($attachment->ID, $size='thumbnail', $icon = false);
    		}
    	}
    	echo '<img src="' . $first_image[0] . '" width="' . $first_image[1] . '" height="' . $first_image[2] . '"  alt="" />';
    }

    to your theme’s functions.php file. Then edit your archive template and try incorporating:

    <?php
    $thumb_width = get_option('thumbnail_size_w');
    $thumb_height = get_option('thumbnail_size_h');
    ?>
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
    [ usual post heading stuff ]
    
    <?php my_post_image( $post, $thumb_width, $thumb_height );
    the_excerpt();?>
    
    [ usual post footer stuff ]
    
    <?php else:?>
    <?php endif;?>
Viewing 1 replies (of 1 total)
  • The topic ‘Showing exceprt and thumbnail on archives’ is closed to new replies.