“Recently Popular” WordPress Plugin
*** UPDATE ***
Please Read This Post If You've Been Experiencing Problems
Download the Recently Popular plugin I've used a few different plugins to manage the most popular post display on my sidebar. None of them behaved quite the way I wanted. The two major groups and their issues for me were:
- Post counts last forever: This is a big deal if an article gets Dugg or Slashdotted. That post may live at the top of your most popular list long past its useful lifespan.
- Formula-based: These use some formula of views, comments, and who-knows-what-else to try and derive what is most popular. These also count things into perpetuity, but generally they discount dated items as they age. The fact that views aren't dated is still a problem.
I knew what I wanted. I wanted a popularity meter that I could tell "Show the posts that have been most viewed over the last 7 days." Or 3 weeks. Or 12 hours. Or whatever. However I couldn't find it. So I wrote a plugin (with widget!) to do just that. It records hits to any post or page on your site by any user who isn't logged in, then allows you to display the most active ones for your defined time period on your sidebar.
The widget can be added to your sidebar more than once, so if you want to show the most popular over the last five days and the most popular over the last month you can.
Output formatting
The widget supports formatting strings for items in the results. These formatting strings accept HTML, so you can be as creative as you want. The template supports four tags: %post_url% - the post's permalink %post_title% - the post's title %hits% - the number of qualifying views %display_name% - the post's author To simply show the post titles as links to the post you would use this tag (note: this is the default output format):
<a href="%post_url">%post_title%</a>
The widget defines this and two other typical tags that you to simply click on and use without having to figure out the templating.
Using in Themes Without Widget Support
To install this plugin in a theme that doesn't support widgets you add something similar to this to your template:
<ul> <?php get_recently_popular($interval_length, $interval_type, $limit, $user_type, $post_type, $output_format, $categories); ?> </ul>
Where:
- $interval_length is the number of $interval_type to consider.
- $interval_type is the type of interval. This needs to be the string HOUR, DAY, WEEK, or MONTH
- $limit is the maximum number of posts to display.
- $user_type is the types of users you want to count views from. 0 = All, 1 = Anonymous only, 2 = Registered only.
- $post_type is the types of posts you want to count views from. 0 = All, 1 = Pages only, 2 = Posts only.
- $output_format is a formatting string for how to display each result in the list.
- $categories is a string formatted as: " 'Category 1', 'Category 2' ", including the single quotes, with every category you wish to include listed. If this value is not supplied or is an empty string then all categories are considered.
For example, this will show the ten most viewed pages and posts in the past one month by users who weren't logged in:
<ul> <?php get_recently_popular(1, 'MONTH', 10, 1, 0); ?> </ul>
While this will show the five most viewed posts in the past two weeks by all users:
<ul> <?php get_recently_popular(2, 'WEEK', 5, 0, 2); ?> </ul>



[...] original here: "Recently Popular" WordPress Plugin | Eric Biven’s Blog This entry was posted on Wednesday, December 3rd, 2008 and is filed under Wordpress Hosting. You [...]
The issue with WP-Postviews that displayed pageviews for each article is that it counted page reloads by the same user in the same session, and didn’t ignore admin views.
Maybe it’d be easier to hook into the Wassup plugin:
http://www.wpwp.org
@Adrian: Thanks for the heads up and I’ll certainly be looking to Wassup for inspiration, just like I did WP-Postviews. I considered plugging into an existing stats package but abandoned it for a couple of reasons.
First, which stats package(s) would I work with? If I chose one I would severely limit the potential users. If I worked with more than one it would add a great deal of complexity and overhead to the code. It also then relies on others for the data to be correct.
Second, not all stats packages can be tied in to. I personally use a log-parsing stats package locally and Google Analytics, neither of which would be convenient or reasonable for the widget to use as a data source.
In the end the data storage needs for this plugin are very, very modest. The table has two columns: the timestamp of the hit and the page that was hit. It seemed silly to require anything more just to use this plugin.
Огромное спасибо за потрясающие идеи!!! Буду следить за блогом, много всего интересного. А мой блог о науке, надеюсь, тоже понравится ;)
Thanks for the plugin, was looking for it for a while
Hey bro,
How I install the plugin or how to show it in sidebar if my theme isnt widgetized ?
please sos!!!!
@MedelliNStyle:
I’ve updated the article above to include those instructions. Thanks for pointing out that I still hadn’t done that.
Hi!
How can I configure your plugin to only show recently popular posts? Now its showing popular pages aswell.
Great plugin!
/ross
@Ross:
That feature is in the works. I had begun work to add that as a configuration on the settings page (which is also in a future release), but now that the widget can be added multiple times it makes more sense for that setting to be on the widget. Hopefully I can get that moved over this weekend and possibly do a 0.3.x release.
Glad you like it.
0.4 has been released. The widget was altered in this version to allow the user even more flexibility in choosing what items to count. Get it from the link at the top of this page.
Thank you for the 0.4 update, works like a charm!
I pasted the line inside wordpress\wp-admin\includes\template.php
But I am unable to see Popular count in the home page and also in the admin panel. I am currently using revoultionary theme2.0. Does this have an effect ? Kindly help.
@Prabhu:
First, you should take anything out of the template.php file that you have added. Next, what version of WordPress do you have?
Thanks. This is the plugin I’ve been looking for a long time.
Works perfectly – Great stuff!
Hi Eric,
thank you for a great plugin!
I’m already using WP_postviews but really want to add timespan function and your plugin solves that…but, I was wondering is there any way we can split this by categories (like, popular from category) ? As I’m already using this method for the site (www.tip.ba) with help of wp_postviews template function, php_exec and slayer’s custom widgets plugins(messed, huh).
Having a widget option or template function for category breakdown would be great and I would certainly donate to have it!
@perke:
That’s a fantastic idea. Consider it done.
I have a release that should go out today or tomorrow that adds formatting to the output so that you can choose how the items in the list look. I’ll work on this next.
[...] Recently Popular [...]
Using WP2.7, and doing an automatic install, I can’t find any of the configuration panes contained within the screenshots. There is no “Recently Popular” widget to choose from.
Any ideas?
@Mike:
When you install the plugin there will be two plugins to enable under “Plugins -> Installed”. The first is the base “Recently Popular” which does the data gathering and supports non-widgetized themes, the second is the “Recently Popular Widget”. The widget is split out so that it doesn’t have to load for people who don’t have widgetized themes. If you’ve activated both of them and the widget still doesn’t show up then let me know what OS, web server, and PHP version you’re using and I’ll see what I can do.
[...] Recently Popular [...]
[...] Recently Popular [...]
Great news Eric!
Can’t wait to see it in action :)
Thanks a bunch!
[...] Recently Popular [...]
Hello
One question, will it work with super-cache plugin installed?
Thanks again for your great plugin.
Yes, it works perfectly with the WP Super Cache plugin, I use it in conjunction with Recently Popular on this site. It will correctly record all page views. The one thing to be aware of is that any cached page can’t have completely updated counts since it is, by definition, serving cached data.
[...] Recently Popular [...]
Fantastic plugin! Does just about everything I’m after. As perke mentioned, the ability to specify a category for each iteration would be greatly appreciated.
I’ve tried several “popular posts” plugins over the past week and yours comes closest to what I’m after. If you added category functionality, it would be perfect.
@Matt Brett:
Thanks for the kind words. I plan to have category support by 2009-01-04.
That’s great news, Eric. Thanks! The client project I’m working on launches on the 10th of January, so that will be just in time.
[...] Recently Popular [...]
[...] Recently Popular [...]
[...] Recently Popular [...]
[...] Recently Popular [...]
Thanks for your fantastic plugin, I really love it.
Here’s one suggestion I have though. Do you think we could have an option to exclude some of the pages/posts from the chart? I have some dynamic pages which make use of GET parameters to show different contents (one of them a forum). That means users load these pages over and over again, and they can easily top the other regular yet more substantial posts/pages.. Now I have do to the database and remove these page hits from time to time to avoid them showing up on the chart, but if I can simply exclude them it’ll be really nice.
@Thomas Tsoi:
I’m glad you like it. I can certainly add the ability to ignore certain post/page IDs in the future. It sounds like maybe it would be more useful if you could not record any hits to specific ULRs using wildcard matching and/or be able to support hits to non-WordPress pages.
[...] January 3, 20092:46 am WordPress Plugins 01/03/2009 Recently Popular records hits to any post or page on your site by any user who isn’t logged in, then allows [...]
hi. Thanks for plugin
perfect.
Regards
Ok everyone: 0.4.7 is out a day early. Happy new year.
I was happy to see the plugin update notification in my WP-Admin this morning – thanks for following through, Eric!
I’m able to do exactly what I need for my client site now. But I do have a suggestion and one more request.
If instead of category name, the ID could be used – that would prevent any unnecessary template updates if the category name were to change.
I’m not sure what’s involved, but would it be possible to include child categories automatically? Again, trying to ensure my client can make changes to their category structure without having to update templates all the time. The site I’m working on has 3 main categories, and child categories will be added/removed regularly. Which means, I’ll have to jump in there and update the templates each and every time. Where as, if children were supported, I’d just have to specify the main categories and leave it be.
@Matt:
I can certainly look into that. I don’t think the child category bit would be too hard, but right now I’m talking without looking. I’ll let you know when I’ve had some time to look at it.
Hi!
First; seems to be a great plugin, but…
I´ll use the plugin in my template – so I put the code …. in my template. But it does not work. Only 1 post is shown, an these one is not really popular…. :) So, what´s wrong?
Please help! :)
@Thomas:
Can you show me exactly what you put in your template? That would certainly help diagnose any issues.
Sorry Eric, my mistake! :(
Everything´s fine! So your plugin counts the “readers” since instalation. And I thought, that all “readers” are count since the article was wrote.
And sorry for my bad school-english. :/
So far. Greets from germany
Thomas
@Thomas:
No problem. WordPress doesn’t track the data necessary for this plugin, so it adds a table and populates it with each page view. So when it’s first installed it won’t have anything to show.
If anyone is concerned about having an empty list display then you can just enable the plugin and not put it on a page anywhere. It will collect data whether it is displaying data or not, then when you feel like you’ve collected enough data start displaying it.
Hi Eric, great work with the changes! Thanks much and donation is on the way.
Can I feel free to ask another question in regards of further hacking your plugin via email?
@perke:
Fire away. I sometimes don’t get my email more than twice a day, but it will get a response.
Thank you for creating a plugin that does what I want and actually works. You have earned yourself a ‘mini post’ on my blog.
[...] Biven’s ‘Recently Popular’ Wordpress plugin just works. Rate this: 2.8 Share and [...]
@Matt:
I haven’t forgotten about you. I’m trying to weigh your request for using ids vs the people who are using the function call directly and not using the widget. Using category ids for them would be difficult at best. I may take some sort of hybrid approach, but I need to weigh that against the increased complexity of the joins.
[...] – produce a list of popular posts for specified categories. That was until I found the brand new, Recently Popular plugin. At the time I stumbled upon it, the functionality I was after wasn’t quite there. But after [...]