Display last months most commented posts as thumbnail

This snippet will display last months most commented posts as thumbnails. Add the first snippet to the functions.php of your wordpress theme then add the second snippet where you wish to display the thumbnails. I currently use this snippet on http://wpsnipp.com after the third post if you wanted to see it in action.

 

 

function most_wps_popular_thumbnail(){
$current_month = date('n');
if($current_month==1){ $last_month=12; }else{ $last_month=$current_month-1; }
$args = array(
'posts_per_page' => 4,
'monthnum'       => $last_month,
'orderby'        => 'comment_count',
);
?>
<h1>Most popular snippets</h1>
<?php query_posts($args); ?>
<?php  while (have_posts()) : the_post(); ?>
<a href="<?php the_permalink(); ?>" title="<? the_title(); ?>"><?php the_post_thumbnail( 'thumbnail' ); ?></a>
<? endwhile; ?>
<?
wp_reset_query();
}

<? most_wps_popular_thumbnail(); ?>

Be Sociable, Share!

Leave a comment