How to Create WordPress Popular Post with Thumbnail?

Last week, I have tried some tweak to add WordPress Popular Post with Thumbnail module in the tabbed bar. This tweak will display numbers of popular post based on comments count in specific post. Meaning, the popularity of the post was determined by comment’s count. You can easily change number of post displayed in the module by altering the post number in the code.

In this post, I will show you the easy way to create this module. I have added thumbnail function by returning the key value of “thumbnail” into custom fields. You can learn more about custom field here.

So, enjoy the tutorial!

Easy Step to Create Popular Post with Thumbnail in WordPress

1. Create & specify your Div to add the popular post module. For me, I will use my current tabbed bar in Sidebar.

2. Copy and paste this code into specific Div Id/Class.

Popular Post (With Thumbnail)

<?php $result = $wpdb->get_results("SELECT comment_count,ID,post_title FROM $wpdb->posts ORDER BY comment_count DESC LIMIT 0 , 5");
foreach ($result as $post) {setup_postdata($post);$postid = $post->ID;$title = $post->post_title;$commentcount = $post->comment_count;
if ($commentcount != 0) { ?>
<?php if( get_post_meta($post->ID, "thumbnail", true) ): ?>
<a href="<?php the_permalink() ?>" rel="bookmark"><img style="float:left;margin:0px 10px 0px 0px;" src="<?php echo get_post_meta($post->ID, "thumbnail", true); ?>" alt="<?php the_title(); ?>" /></a>
<?php else: ?>
<a href="<?php the_permalink() ?>" rel="bookmark"><img style="float:left;margin:0px 10px 0px 0px;"  src="<?php bloginfo('template_url'); ?>/images/default_thumbnail.png" alt="<?php the_title(); ?>" /></a>
<?php endif; ?>
<b><a href="<?php echo get_permalink($postid); ?>" rel="bookmark" title="<?php echo $title ?>"><?php echo $title ?></a></b>
<?php } } ?>

3. If you prefer Popular Post module with no thumbnail. Just add this code:

Popular Post (No Thumbnail)

<?php $result = $wpdb->get_results("SELECT comment_count,ID,post_title FROM $wpdb->posts ORDER BY comment_count DESC LIMIT 0 , 5");
foreach ($result as $post) {setup_postdata($post);$postid = $post->ID;$title = $post->post_title;$commentcount = $post->comment_count;
if ($commentcount != 0) { ?>
<b><a href="<?php echo get_permalink($postid); ?>" rel="bookmark" title="<?php echo $title ?>"><?php echo $title ?></a></b>
<?php } } ?>

4. Save your themes and you’re done!. This is how my Popular Post with Thumbnail looks like =)
Easy Way to Create WordPress Popular Post with Thumbnail?

The Tags: , , , , ,
Incoming Search: yhs-002, wordpress popular posts thumbnail, popular posts with thumbnail wordpress, popular post with thumbnail wordpress, php wordpress posts with thumbnails, Wordpress Popular Posts, wordpress popular posts thumbnails no margin, wordpress popular posts thumbnail custom field, wordpress post thumbnail, wordpress update title thubnail post_title, wordpress popular posts style, wordpress popular post thumbnail, popular posts with thumbnails wordpress, popular posts with thumbnails, popular post wordpress thumbnail, popular post wordpress, popular post thumbnail wordpress, most popular post thumbnail, how to create a php bookmark, $wpdb- get_results thumbnail
  • Pingback: How to Create WordPress Popular Post with Thumbnail | Cariblogger.com | Design Blog

  • http://www.legendagroup.edu.my BTEC HND

    Nice tutorial!

  • http://technolengk.com/ olengk

    nice post.. thx

  • http://www.technopus.com dhaval

    Thanks buddy..
    really informative…

  • http://deluxejournal.com oto

    Thanks bro! i hope this works for me.

  • http://www.nonstopcars.com nonStopCars

    I have applied it to my website, thanks again. Sorry, a silly question, it can affect the speed of the website?

  • http://www.itechminder.com/ Zareen Khan

    Thanks to useful links and information.I really enjoy this tip.Great job keep it up and post more tips………..

  • http://nhatrangtravel24h.com tuan

    hi friend!
    how to create Popular Post in create post editor!?
    thanks