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
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.
Donations
If you’d like to help improve development of this plugin and others that I have written, you can donate with PayPal.
Usage
- Use as a widget in the sidebar.
- Use as a dedicated function inside a post or page. Somewhere in the template include the text
<?php most_popular(1); ?>and you’ll see a simple list. The 1 ensures the list is displayed as a regular list instead of as part of a sidebar.
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, 2008
* Initial release
v1.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
Something you want changed about it? Please leave a comment.

106 responses so far ↓
1 baron // Aug 19, 2008 at 12:14 pm
hi. Thanks for plugin
perfect.
Regards
2 Rosenstand // Aug 21, 2008 at 2:57 pm
Hi
Your download link is broken…
3 combos // Aug 21, 2008 at 3:01 pm
thanks but download link is not working right now
4 Mike // Aug 21, 2008 at 3:57 pm
I click on the download link and get an “Oops” page. Where can I find the file? Thanks.
5 wesg // Aug 21, 2008 at 4:35 pm
Thank you to everyone who noticed the link was not working. It has been updated to link to the Wordpress directory.
6 Go Holga // Aug 21, 2008 at 7:12 pm
probably one of the best plugins around. I love this one.
7 pickupjojo // Aug 21, 2008 at 7:35 pm
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 // Aug 21, 2008 at 11:54 pm
@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 // Sep 6, 2008 at 9:48 pm
Has anyone tried this plugin on WP2.6 and Super Cache? Does it conflict with Super Cache in any way?
Cheers
Chris
10 wesg // Sep 6, 2008 at 10:19 pm
@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 // Sep 7, 2008 at 11:14 am
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 // Sep 7, 2008 at 7:59 pm
Very nice plugin, easy and useful. Congratulations!
13 Crane Machine // Sep 21, 2008 at 10:48 am
Very Good~!!
14 Rick // Nov 29, 2008 at 12:28 pm
This worked perfectly. Some others I tried would not work. You should write more widgets.
15 wesg // Nov 29, 2008 at 1:34 pm
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 // Dec 6, 2008 at 9:05 am
Nice plugin, lovely!
17 Ashok // Feb 19, 2009 at 7:12 am
hi,
how can i create widgets in my page
18 Steve // Mar 16, 2009 at 2:08 pm
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 // Mar 16, 2009 at 10:32 pm
@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 // Apr 7, 2009 at 11:01 am
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 // Apr 14, 2009 at 11:57 pm
@Brad: I will add that functionality to the next version. Thanks for the suggestion!
22 Anderson // Apr 15, 2009 at 8:05 am
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 // Apr 15, 2009 at 6:22 pm
@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 // Apr 16, 2009 at 3:15 pm
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 // Apr 24, 2009 at 8:18 pm
Very nice plugin and I just installed in my blog and it works well. Thank you for the useful tool.
26 Crusinlife // Apr 25, 2009 at 5:10 am
good plugin thank : D
27 kiran // May 8, 2009 at 5:15 am
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 Schul-Kritik.de // May 19, 2009 at 8:44 am
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 // May 20, 2009 at 10:00 pm
@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 // May 22, 2009 at 4:28 am
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 // May 28, 2009 at 3:17 pm
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 // Jun 11, 2009 at 9:33 am
Hi Wesg
Thanks for the plugin man. Now I can add it to my blog
CHEERS
33 Dawn // Jun 19, 2009 at 11:17 pm
Love this widget!!!
34 Bjarke - Forzajob // Jun 21, 2009 at 11:31 am
great plugin, just used it on my site.
35 Semih // Jun 23, 2009 at 7:51 am
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 // Jun 23, 2009 at 7:48 pm
@Semih: I’ve added a PayPal button to this page. Thanks for using the plugin!
37 watch video // Jul 13, 2009 at 3:54 pm
Thanks. This plugin just works great.
38 Alessandro Astarita // Jul 15, 2009 at 12:27 pm
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 // Jul 15, 2009 at 4:26 pm
@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 // Jul 16, 2009 at 12:06 pm
Great plugin! Is it possible to exclude certain categories or posts from showing up on the list?
41 wesg // Jul 18, 2009 at 12:48 pm
@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 // Jul 20, 2009 at 3:58 am
Great – thank you very much!
43 Fat Boy // Jul 25, 2009 at 2:29 pm
This is a great plugin… the only thing is, my draft posts show up… is there anyway to stop that?
44 wesg // Jul 25, 2009 at 7:43 pm
@Fat Boy: I’ll check the code again, because I didn’t want the drafts to show up in the widget.
45 Stanley // Jul 28, 2009 at 10:36 am
Great plugin!
i had apply on my site~
thanks
46 Andy Killen // Jul 30, 2009 at 5:41 am
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 Andy Killen // Jul 30, 2009 at 5:41 am
oh and it’s being used on this site http://www.thecommonwealthconversation.org/
48 Naufrago // Aug 2, 2009 at 5:25 am
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
49 Larry // Aug 5, 2009 at 8:35 am
My widget’s select lists no longer show “uncategorized” as an option. This may have happened when I upgraded to 2.8.3.
50 Billige mobiler // Aug 6, 2009 at 3:32 am
great post. i could really use this one.
51 GTL Media // Aug 6, 2009 at 4:05 pm
Mine no longer works with 2.8.3 period plus, as with Larry above, there is no “Uncategorized” option for me either, FWIW…
52 Jason Beaird // Aug 10, 2009 at 11:06 am
This is a great plugin, but I’m having the same problem as Andy Killen above. I need to add a class to the list, but in the custom HTML field, the plugin adds escape characters on each save and then doesn’t strip them out on the display end. So as far as I can see, there’s no way to add single or double quotes, and therefore no way to add CSS classes.
53 Thomas // Aug 10, 2009 at 5:52 pm
Great Job…this is exactly what I have been looking for!
54 Teknoloji haberleri // Aug 11, 2009 at 12:46 pm
thank you admin
55 Onore // Aug 14, 2009 at 4:44 pm
Simple and Great PlugIn – Thanks =)
56 Scott // Aug 16, 2009 at 2:06 pm
Having the same issue as Naufrago above, except mine is line 79. This is on 2.8.4. Have used it before and its an awesome plugin, but now I don’t know what’s up. Anything I can do?
57 alienman // Aug 16, 2009 at 6:22 pm
thank you for this handy and easy plugin! got it working in a mere 7 seconds!
58 Bayrak // Aug 18, 2009 at 5:22 am
Thank you plugin
59 Sean James // Aug 28, 2009 at 10:26 pm
Great plugin, just installed it on my blog but i am having a problem:
http://potleetopw.net/
As you can see the Most Popular Posts widget is not styled like the rest.
60 Tiffany // Sep 3, 2009 at 12:18 am
Is there a way to alter the look of the title? When I install the widget, the title turns out looking very large and bold. Far more so than my other headers in my sidebar. I’d also like to change the color of the title text.
Is this possible?
Thanks
Tiffany
61 Teknoloji Haberleri // Sep 8, 2009 at 8:19 pm
thank you plugin supper
62 T.M. // Sep 18, 2009 at 8:11 pm
Same problem with my site…
Warning: Invalid argument supplied for foreach() in …/plugins/most-popular-posts/most-popular.php on line 79
Any ideas? I’m not sure what this means or how to fix it.
Thanks in advance for your help. I’ve been using this plugin for a long time now and hope to continue doing so.
63 Steven // Sep 19, 2009 at 4:22 pm
Hello! Great little plugin…
One question… I am using WPML to run a multilingual site. Is there any way that this can filter only posts in certain languages? So, if someone is on the spanish site, it only shows the spanish posts and not all the languages as it does now?
Thanks!
64 wesg // Sep 20, 2009 at 5:25 pm
@T.M.: Thanks for the message, I will look into it.
@Steven: I’ll also investigate the multilingual site option. Thanks for the suggestion.
65 ahmed // Sep 21, 2009 at 10:09 pm
hello
i need change stayle ?
66 chat // Oct 1, 2009 at 7:34 am
Great plugin! i had apply on my site~ thanks you
67 Gray // Oct 5, 2009 at 10:10 pm
Hi, I’m using this great plugin with the Pixel theme…I’m having a tiny problem where the widget is appearing further to the left than it should be, sticking out from the sidebar and doesn’t seem to be inside a box like other widgets I have. Any idea how to fix this?
68 bayrak // Oct 12, 2009 at 5:03 pm
thank you for sharing Congratulations on a very beautiful designed site
69 Kenny Gor // Oct 16, 2009 at 1:18 pm
Anybody having problem with the thumbnail? it doesnt want to align to the left.
please help. great plugin
70 BGLH // Oct 19, 2009 at 3:59 pm
Hey Wes,
This plugin is awesome, and I’ve used it on my site, but I am trying to figure out how to edit the line height so it doesn’t look so spacey in the sidebar.
How can I edit the plug in to decrease the line height?
Thanks!!
71 Simon // Oct 26, 2009 at 10:27 am
Hello,
nice Plugin.
But can you do it even more customizeable?
For Example:
The Option “Put in a a Parent UL Tag” is nice, but i would like to have it in a parent div instead the ul. maybe you could also rename the standard class to widget_…. to go conform with other widgets and css rules.
thank you so far.
72 Simon // Oct 26, 2009 at 10:39 am
Another Great move would be to place it in the wordpress repository so that updates will be displayed in the wordpress dashboard.
btw. Im using wordpress mu 2.8.4 and your plugin works like a charme
73 wesg // Oct 26, 2009 at 11:31 am
@Simon: Thank you for the valuable comments. I will take them into account when I update next. The widget is already in the WordPress repository, but blog panels can sometimes take a few days to show the update.
74 Kenny Gor // Oct 28, 2009 at 3:32 pm
Hey Wes – sorry to bother you once again… any idea why my thumbnails are not aligned with the headers? I’ve tried it in 2 different themes, same thing. I’m not too good in CSS but I can give a donation for anyone who’s willing to help. thanks a million
75 Kenny Gor // Oct 28, 2009 at 3:36 pm
Here is my content format:
{image}{title}{summary} {stats}
76 e-okul // Oct 30, 2009 at 9:58 am
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.
77 Anders Holm // Nov 1, 2009 at 7:50 am
Nice plugin… Do it support all WP versions or is there a “version minimum” to be working ?
78 wesg // Nov 2, 2009 at 11:51 pm
@Anders Holm: I test each version of the plugin with the most recent version of WordPress, but I imagine it will work as far back as 2.7. Any early than that and you may run into different behaviour.
79 doug // Nov 6, 2009 at 10:20 pm
This would be most useful if I could restrict the timeframe of popular posts to like the last week or month.
80 Reino // Nov 8, 2009 at 9:16 am
Is there any way to show “most viewed posts of last month”, so not to show most viewed posts of all time but show posts of last 3 months (or 1). Would be great!
81 wesg // Nov 15, 2009 at 12:30 am
Thanks for the comments and suggestions. I will look into these features for the next update when I have time.
82 bayrakçı // Nov 15, 2009 at 7:17 am
thamnk you very nice
83 Ninja // Nov 22, 2009 at 2:57 pm
Just downloaded the newest update and now it displays “popular posts” incorrectly. It appears to be taking my least popular content (posts with 0 comments) and displaying them now. It worked fine up until the update. What gives?
84 wesg // Nov 22, 2009 at 4:34 pm
@Ninja: Thanks for catching that! It was a tiny code error during the update, but it’s been fixed now. A new version should be available shortly.
85 Ninja // Nov 22, 2009 at 5:17 pm
Thanks Wesg appreciate the timely fix. I was looking at other popular post widgets, but they suck compare to yours. Glad I can stick with it
86 Battlefield 3 // Nov 23, 2009 at 1:34 am
Thanks for this i will use this for my article-nerd.com website, it is an article submission website, this plugin should be very handy, thanks for your hard work !
87 PG // Dec 1, 2009 at 6:06 am
I am using the function in my side bar but cannot find any of the settings to change.
I am not using widgets.
I am unsure about the usage and how to stop the comment counts appearing after the post name.
help is greatly appreciated
PG
88 wes // Dec 2, 2009 at 6:23 am
cool plugin! just curious, what data does this pull from to know which posts are the most popular?
89 Benjamin Rama // Dec 2, 2009 at 7:14 am
dude nice plugin – just the text is tiny – can you explin how to chneg the sixze of teh text pls thanx
90 wesg // Dec 3, 2009 at 3:30 pm
@Benjamin Rama: I’ve set up the plugin so that text can be modified from the CSS file of your template. If it doesn’t match the surrounding text, experiment with the “nesting list item” option.
91 Mark // Dec 13, 2009 at 12:38 pm
I would like to use the plugin on a page (only, and not in the sidebar–I use an EXEC-PHP plugin) and understand how to do that with . However, two things:
1. In order to configure it I have to insert the widget into a sidebar, configure, and then remove it from the sidebar. It would be helpful to be place to have the configuration options in the Admin.
2. Also, or instead of, tell us how to insert the configuration parameters right into , if that is possible. Then, I can tell it to display as I want when I place it on a page. And the great thing about this would be that I could then have multiple instances of it (i.e., Most commented all time, and another for most commented last month). This would be VERY helpful.
3. Add the ability to sort the list with the most recently commented article at the top, descending order.
The reason I would like these things is that I am setting up a page called Forum. Admittedly, it would be no where near a forum, but I could quickly show the readers “where the action is” in several lists, which would dramatically increase page view. I thinkj these changes would open up new opportunities for your plugin.
Thanks for you consideration, and love what you’ve done so far.
92 wesg // Dec 13, 2009 at 1:51 pm
@Mark: thanks for those comments. This week I will be reviewing my plugins and making suggested changes. I think one of those changes will be an admin panel to override the widget properties.
93 Glenn // Dec 18, 2009 at 6:39 am
I just updated to the latest version of this plugin. Now it only says “No posts to display.”
94 wesg // Dec 18, 2009 at 5:45 pm
@Glenn: This is because no posts fulfill the criteria in the settings. Have you tried different conditions?
95 sahibinden // Dec 21, 2009 at 9:45 pm
thanks for article
96 Ben // Dec 28, 2009 at 11:32 pm
Great plugin, however, I am having problems styling it. I got the list items to work right but the title is large and bold. Cannot seem to get it to match the other titiles on the sidebar. Tried the nest option but didnt work.
97 Tomi // Dec 30, 2009 at 3:52 am
Hiya!
It is worked on WordPress 2.9?
98 Hazel // Dec 31, 2009 at 6:34 pm
Hi, Can it be most viewed page or post? Thnaks
99 shoaib // Jan 10, 2010 at 2:36 pm
nice plugin and most of all its really clean.thnx
100 bayrak // Feb 2, 2010 at 8:02 am
thank you for sharing
101 Gajogeje // Feb 5, 2010 at 8:34 am
Hi, it´s a great plugin, but i have a question. In the new version, the options are in the widget, but if i want paste the code in my template, how can i manage de options?
thankyou.
102 wesg // Feb 11, 2010 at 7:51 pm
@Gajogeje: Currently the widget settings change a single function, meaning settings affect both a widget and a function, should you use one. In a future version I will try to include multiple instances of the widget.
103 Brook Lenox // Feb 12, 2010 at 6:52 pm
Hi,
Really like this plug in! (but have an issue).
I’ve got WP 2.9.1.
In internet explorer the posts look fine, but in Firefox 3.5.7 the post titles have funny little bullets and the text is tiny.
Is there something I can do about that?
http://www.onlinemarketingrant.com
Thanks,
Brook
104 Brook Lenox // Feb 12, 2010 at 6:58 pm
Hi…also is there somewhere it explains how to use the formatting options (parent list item class, child UL class, list item class).
I’m clueless here. Thanks!!!
Brook
105 dilek // Feb 15, 2010 at 5:00 am
Perfect plug-in and works without problem. Thank you very much.
106 wesg // Feb 16, 2010 at 11:40 am
@Brook Lenox: I’ll look to get another tutorial online shortly. Thanks for the comment!
Leave a Comment