views:

331

answers:

2

I'd like to show a list of most popular posts sorted by number of views.

I'd like to show small thumbnails (the same image(s) used in the posts just resized to fit) on left, and excerpt on right. So the formatting would look like:

[#1 Post Title]
[80x80 thumbnail] [excerpt, limit to x chars]

[#2 Post Title]
[80x80 thumbnail] [excerpt, limit to x chars]

[#3 Post Title]
[80x80 thumbnail] [excerpt, limit to x chars]

... upto 5 posts

Is there a plugin available for this? If can be achieved by simply using wordpress template tags, I'd prefer that over a 3rd party plugin. But important to me is display formatting, I need thumbnails on left.

Many thanks

+1  A: 

You can install a plugin like Wordpress popular posts. This plugin can't do exactly what you want, but it records pageviews in the database, and you can use that data in your theme by writing code like the following:

$right_now = gmdate("Y-m-d");
$qstr = "
    SELECT wposts.* 
    FROM $wpdb->posts wposts, 
    (select postid, sum(pageviews) pageviews 
     from $pageviews_table 
     where day >= '$right_now' - INTERVAL 30 DAY
     group by postid) pv
    WHERE wposts.post_status = 'publish' 
    AND wposts.post_type = 'post'
    AND wposts.ID = pv.postid
    AND wposts.post_date >= '$right_now' - INTERVAL 30 DAY
    ORDER BY pv.pageviews DESC
    LIMIT 10
 ";

$max_most_read = 5; // Number of "most read-spots" 
$posts = $wpdb->get_results($qstr);
if ($posts) {
   $i = 0;
    foreach ($posts as $post) {
     setup_postdata($post);
     if ($i < $max_most_read) {
      $category = get_the_category();

      # Now you can use $post->post_content to extract image tag and excerpt
      # See http://www.wprecipes.com/how-to-get-the-first-image-from-the-post-and-display-it
      # on how to extract and resize first image

      $i++;
     }
    }
}
windyjonas
A: 

Found a plugin that works perfectly.

Nimbuz