WordPress Widget: Most Popular Posts

I’m working on a revamp to the blog, and in my search for excellence I was unable to find a widget to display a link to the most popular posts according to the number of comments — something I want to add to “wesg 2.0”.

After finding an excellent tutorial on creating WP widget admin panels, I decided to make my own to have complete control.

The result of my labour is a very simple widget that displays a link to the pages with the most number of comments. You can customize the title of the widget, the number of posts to display and comment count.

You can also limit or skip single categories.

Download the Most Popular Posts widget now

Acknowledgements

  • Ricky — MySQL query to exclude posts with multiple categories
  • Ashish J. — Hindi translation and beta test
  • Branco — Slovak translation

Installation

  • Upload the file most-popular.php to your WordPress plugins folder.
  • Activate the plugin from the admin panel.
  • Go to the Widget admin page and customize the widget.

If you’d like to help improve development of this plugin and others that I have written, you can donate with PayPal.




Usage

Current usage is limited to widget only. Keep watching this to see if the template function returns.

Defaults

  • Title: Most Popular
  • Show links to 5 posts
  • Display comment count
  • Posts with zero comments are included
  • All categories are included
  • No categories are excluded

Changelog

v1.0 — August 14, 2008v1.1 — August 21, 2008
* Added support for using the list as a function in a post

v1.2 — January 6, 2009
* Updated for WordPress 2.7
* Add localization capability

v1.3 — July 18, 2009
* Added categories to exclude
* Added categories to include
* Switch off nonzero comment posts

v1.4 — August 6, 2009
* Added exclude category checkbox
* Added include category checkbox
* Stopped drafts from including

v1.4.1 — August 10, 2009
* Exclude posts with multiple categories

v1.4.2 — October 24, 2009
* Added support for custom CSS classes to match website theme

v1.4.3 — November 21, 2009
* Added ability to limit comments to posts within a certain timeframe

v1.5 — July 11, 2010
* Updated for WP3.0 compatibility and conventions
* Added reverse order option

v1.6 — July 18, 2010
* Repaired category and date behaviour

v1.6.1 — September 23, 2012
* Applied bugfixes for WordPress API updates

v1.6.2 — February 13, 2013
* Added Slovak translation

Something you want changed about it? Please leave a comment.

Tagged with: , , ,
141 comments on “WordPress Widget: Most Popular Posts
  1. baron says:

    hi. Thanks for plugin

    perfect.

    Regards

  2. Rosenstand says:

    Hi

    Your download link is broken…

  3. combos says:

    thanks but download link is not working right now 🙂

  4. Mike says:

    I click on the download link and get an “Oops” page. Where can I find the file? Thanks.

  5. wesg says:

    Thank you to everyone who noticed the link was not working. It has been updated to link to the WordPress directory.

  6. Go Holga says:

    probably one of the best plugins around. I love this one.

  7. pickupjojo says:

    The same but not only in a widget, I need a real plugin to use with a fonction (mostpopularposts() for example), please it would be very nice! 🙂
    Great work nevertheless. 😉

  8. wesg says:

    @pickupjojo: Your wish is my command. Version 1.1 outlines how to use the main component as a function. View the examples for details.

  9. Chris says:

    Has anyone tried this plugin on WP2.6 and Super Cache? Does it conflict with Super Cache in any way?

    Cheers

    Chris

  10. wesg says:

    @Chris: My blog is running WP2.6.1 and WP-Cache, along with the widget in the sidebar, and I have not seen any conflicts. I imagine Super Cache would work just the same.

  11. Gary James says:

    Thanks for the plugin.. I had to make one minor tweak to your code – around the title it should look like this:

    Code fixed

    That ensures correct formatting when used in the sidebar.

    Cheers,

    Gary.

  12. Katiero says:

    Very nice plugin, easy and useful. Congratulations!

  13. Crane Machine says:

    Very Good~!!

  14. Rick says:

    This worked perfectly. Some others I tried would not work. You should write more widgets.

  15. wesg says:

    Thanks, Rick, I appreciate it. I write plugins/widgets whenever I think of ideas, so if you have any suggestions, I’d love to hear them!

  16. Paw says:

    Nice plugin, lovely!

  17. Ashok says:

    hi,
    how can i create widgets in my page

  18. Steve says:

    I was wondering if this awesome widget could be configured to work like:

    http://www.pearsonified.com/2008/02/what_every_blogger_needs_to_know_about_categories.php

    What I love about that is that you can specify what posts it shows based on categories and it will show a rotation of posts in that category. Is something like that possible with your widget?

    Thanks.

  19. wesg says:

    @Steve: that’s a good suggestion, and I’ll take a look at it for future versions. The most likely addition would be adding an option for displaying the most popular posts from a specific category.

  20. Brad says:

    What would be most useful is if the plugin only sorted by approved comments rather than by total number ever. The amount of old spam comments showing up throws my list off.

  21. wesg says:

    @Brad: I will add that functionality to the next version. Thanks for the suggestion!

  22. Anderson says:

    Hiii, your plugin works correctly on my WP, but the list are never atualized. I wanna say that all my “popular posts” are always the same, and the views are always 0.
    Is there some code I must write on the single.php to increment the numbers of views of this post on database?
    Sorry for my bad english, I wish you understand me ^^

  23. wesg says:

    @Anderson: this plugin uses the comment count for each post, rather than the number of pageviews to generate the list. That means if there are no comments to the post, you will always see a 0.

  24. Anderson says:

    Awwwwwwwwwwww I understand now hehehe..
    soooo, maybe this weekend I’ll try to make your plugin see the numbers of pageviews ^^
    Hehehe, thx to response, and good job..

  25. Money4Invest says:

    Very nice plugin and I just installed in my blog and it works well. Thank you for the useful tool.

  26. Crusinlife says:

    good plugin thank : D

  27. kiran says:

    Hi,

    Thanks a lot for the widget.
    I changed the query to avoid posts which are inherit. and the comment count is greater then zero and they are not pages. The query line changes as

    $posts = $wpdb->get_results(“SELECT ID, post_title, comment_count FROM $wpdb->posts where post_status=’publish’ and comment_count>0 and post_type=post ORDER BY comment_count DESC LIMIT ” . $options[‘number’] . “”);

  28. Great plugin. But i’ve found a Bug, I think. I am using WordPress 2.71 and there is a little problem. When you look on my Website (schul-kritik.de) you will see it on the right under “Beliebte Artikel”.

    I think the following command is missing: “list-style-position: inside;”

    greetz,
    Artie

  29. wesg says:

    @Shul-Kritik.de: The plugin was designed to function without any formats applied to it. This means you can add CSS code to the list to make it fit into your site.

  30. Media Impact says:

    hello wesg,

    first want to thank you for this nice little plugin. I’ve already implemented on my site http://blog.cleancutmedia.com .

    figured out how to remove the bulletpoint.. now if i can change the color..

  31. Ronit says:

    Is there any way to limit how far back this widget goes? Would it be possible for me to supply a date parameter so that it only displays the most popular posts from the last 30 days?

  32. Danny says:

    Hi Wesg

    Thanks for the plugin man. Now I can add it to my blog

    CHEERS 🙂

  33. Dawn says:

    Love this widget!!!

  34. great plugin, just used it on my site.

  35. Semih says:

    Thanks man. This plugin just works great.

    I will use this plugin on my web site.( i am buildig my web site now )
    in my web site header of the plugin ” En Çok Okunanlar “.. ( means “Most Readed Writings” in Turkish and i am from Turkey.

    And have you a donation account on paypal ?

  36. wesg says:

    @Semih: I’ve added a PayPal button to this page. Thanks for using the plugin!

  37. watch video says:

    Thanks. This plugin just works great.

  38. Hi, thank you for your great plugin.

    The last version of wordpress (2.8) supports revisions. Your plugin is not working properly because it considers every single revision as an indipendent article.

    It’s possible to fix this problem changing following line

    $posts = $wpdb->get_results("SELECT ID, post_title, comment_count FROM $wpdb->posts ORDER BY comment_count DESC LIMIT " . $options['number'] . "");

    with this one:

    $posts = $wpdb->get_results("SELECT ID, post_title, comment_count FROM $wpdb->posts WHERE post_type='post' ORDER BY comment_count DESC LIMIT " . $options['number'] . "");

    Can you publish new version of the plugin to solve the problem for everyone?

    Thank you

    Alex

  39. wesg says:

    @Alessandro Astarita: THank you for pointing this out! I will fix this line, along with a few other problems, and have a new version out shortly.

  40. Naz says:

    Great plugin! Is it possible to exclude certain categories or posts from showing up on the list?

  41. wesg says:

    @Naz: I’m looking at adding this feature to an upcoming version. Ideally, I’m going to have an entry for categories to skip, and categories to include.

  42. Rune Hansen says:

    Great – thank you very much!

  43. Fat Boy says:

    This is a great plugin… the only thing is, my draft posts show up… is there anyway to stop that?

  44. wesg says:

    @Fat Boy: I’ll check the code again, because I didn’t want the drafts to show up in the widget.

  45. Stanley says:

    Great plugin!
    i had apply on my site~
    thanks

  46. Andy Killen says:

    Hey,

    Nice plugin, does what it says on the tin 🙂

    Except I am having a problem with custom HTML, the system is not stripping the escape characters properly. Basically I set a class of and it puts into the code. If I save it again it adds another \ to each of the quotes.

    Thanks in advance, Andy

  47. Naufrago says:

    Thank you for your great plugin.

    I use your great plugin since 2008.

    Now, with v1.3 have a problem:

    Warning: Invalid argument supplied for foreach() in /web/htdocs/www.jggweb.com/home/wp-content/plugins/most-popular-posts/most-popular.php on line 88

    Thanks

  48. Larry says:

    My widget’s select lists no longer show “uncategorized” as an option. This may have happened when I upgraded to 2.8.3.

  49. great post. i could really use this one.