wordpress recent posts with thumbnail

Following code snippet will display recent posts with thumbnail. You can add this code anywhere on your wordpress blog to display recent posts.

<h3>Recently Posts</h3>
global $post;
$myposts = get_posts(array('numberposts' => 5, 'offset' => 0,'post_status'=>'publish'));
foreach($myposts as $post) :
<li class="recent_post_item">
if(has_post_thumbnail()) {
echo '<a href="'.get_permalink().'">';
echo get_the_post_thumbnail($post->ID, array(80,80) );
echo '</a>';
} ?>
<h2><a href="<?php the_permalink(); ?>">
<?php the_title(); ?></a></h2>
<?php endforeach; ?>
<?php wp_reset_query(); ?>

Change array(80,80) if you want to change height and width of the image. right now image is 80px in width and 80px in height.

Leave a Reply

Your email address will not be published. Required fields are marked *