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 the following tags:
- %post_title% – the post’s title
- %post_excerpt% – the post’s excerpt
- %post_url% – the post’s permalink
- %hits% – the number of qualifying views
- %display_name% – the post’s author
- %user_url% – the post author’s URL
- %publish_date% – the post’s publish date
- %category% – the categories the post is in
- %thumbnail_url% – the URL for the post’s thumbnail
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 $rp = new RecentlyPopular(); $rp->get_counts(); ?></ul> |
The get_counts() function takes a single parameter that is an array of the options. The options and their defaults are (default options in bold where applicable):
| Option | Values |
|---|---|
| Description | |
| title | ‘Recently Popular’ |
| Title for the emitted ul. Primarily used by the widget. | |
| enable_categories | true false |
| Determines if category filtering is used. | |
| categories | n/a |
| Category names in single quotes, separated by commas. Ignored if enable_categories is false. | |
| date_format | ‘Y-m-d’ |
| PHP date format to use for date output tags. | |
| default_thumbnail_url | n/a |
| URL to a default thumbnail image to use when no thumbnail is found. Prevents empty images from showing. | |
| display | true false |
| If true the call will emit an unordered list, if false it will return that list from the function call. | |
| interval_type | ‘HOUR’ ‘DAY’ ‘WEEK’ ‘MONTH’ ‘YEAR’ |
| The type of interval to use. | |
| interval_length | 1 |
| Integer value for the number of interval_type to display. | |
| limit | 10 |
| Integer value for the number of results to display. | |
| max_length | 0 |
| Integer value for truncating the title. 0 means no limit. | |
| max_excerpt_length | 0 |
| Integer value for truncating the excerpt. 0 means no limit. | |
| output_format | ‘%post_title%‘ |
| String defining how each result will display. See Output Formatting above. | |
| post_type | RecentlyPopularPostType::ALL RecentlyPopularPostType::PAGES RecentlyPopularPostType::POSTS |
| The type of results to get. | |
| user_type | RecentlyPopularUserType::ALL RecentlyPopularUserType::ANONYMOUS RecentlyPopularUserType::REGISTERED |
| The type of results to get. |
For example, this will show the five most viewed posts (without pages) in the past three weeks by users who weren’t logged in:
<ul><?php $rp = new RecentlyPopular(); $rp->get_counts(array( 'limit' => 5, 'post_type' => RecentlyPopularPostType::POSTS, 'user_type' => RecentlyPopularUserType::ANONYMOUS, 'interval_length' => 3, 'interval_type' => 'WEEK', )); ?></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 [...]