"Recently Popular" WordPress Plugin
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> |



hello again,
I found a solution – its a wordpress-header-problem. Add the following line to your theme @ function.php and it wont add two records:
remove_action(‘wp_head’,'adjacent_posts_rel_link_wp_head’);
more informations under:
http://avinashsing.sunkur.com/2010/02/18/cleaning-up-wordpress-header/
greets
Nice plugin, but it doesn’t properly support non-English characters. Posts with characters from extended character sets do not show up as “popular”, even though site stats show that they are.
@Peter:
I don’t have any blogs that use non-Latin character sets, so it isn’t on my list of things to fix. If you do fix it I’ll gladly accept and integrate a patch.
“Adrian says:
December 6, 2008 at 10:26 am
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.”
I see that this has remained the same. Very nice plugin but can you adjust this? My site is for teenagers and i KNOW SOME WOULD JUST CLICK OVER AND OVER SO I can’t use this great plugin as it is now
@Seawords:
This page is for Recently Popular, not WP-Postviews. Recently Popular allows you to not count views by logged in users.
There’s no good way to determine if two hits are from the same person. You can’t do it by IP because so many people are behind NAT and/or a proxy. You could use cookies but that’s more overhead (and work) than I’m willing to introduce to solve something I don’t perceive as a problem.
Yes. I am testing “recently popular” which allows users to reload page and increase counter.
WP-PostRatings is an example that uses i.p to record users and would appear to be a very popular and efficient plugin.
You do not perceive it as a problem but it is for anyway who has a “serious” site.
Anyways I do appreciate the work that you have done and if I don’t find a plugin that meets my requirements I will look into having this feature added by a freelancer.
The %thumbnail_url% doesn;t get parsed, it just parses as plain %thumbnail_url% , not the actual thumbnail url
Yeah, that’s why I haven’t documented that tag yet. Because I know it doesn’t work. Want to fix that and submit a patch?
Hello
I can’t find any documentation for how to have a thumbnail added. Can this be done?
Thanks
Marko M.
It’s a feature that’s half-implemented.
Yeah, I am having issues with the thumbnail too. It just parses at %thumbnail_url% and doesn’t display anything. I’m on 3.1 too if that helps.
I’m not sure how else to say it: that feature isn’t complete. I know it doesn’t work, that’s why I haven’t documented it. The code to support that tag isn’t in there.
Thanks for creating this much needed and useful plugin.
Hi! Thanks a lot for that great plugin. That is (almost) exactly what I have been looking for.
Is it possible to add Shortcodes? I would like to use the plugin not in the sidebar and not in the template but in Pages and Posts.
Many thanks for your effort!
Hi Eric – Great widget.
I would like to set up a page with your plugin in it. How do I do that ?
My concern with a widget of Most popular is that it could become a self fulfilling prophecy sort of like the Top 10 in the bookstore, no-one looks elsewhere. So a page would work better for me – I think !!
Hey Eric,
Recently upgraded to the most current version by mistake actually, which I understand uses get_recently_popular2 instead, and a different set of parameters? Can you explain a non-widget implementation of this, since the example in the post above still shows use of get_recently_popular?
Also, I notice a lot of comments regarding thumbnail usage above. I’ve actually been using 4.8.3 for a while with successful implementation of thumbnails. Once I get 0.6.3 to actually work on my non-widget implementation, I’d be happy to send over the changes I made to get thumbs working, if you think it will be of any use. I’m not much of a coder, though, so it might be something you’ve already toyed around with. IIRC, I only un-commented out the lines regarding thumbnails, maybe adding one or two lines of code at most to fill in the gaps.
The original function still works, it just calls the new function.
I’d love to get your thumbnail code. I’m currently rewritting the code so it is a good time to integrate new features.
I sent what I had via email to the address on your “Contact Me” page. Let me know if you need anything else from me; I hope it helps.
Can’t wait till %thumbnail_url% will be fixed!
Hey Eric,
Me again. I fixed the issue with my implementation not working… it was an SQL issue causing the table to read as “in use,” so I just deleted it, clearing its data, then reactivated the plugin.
Once I did that, I managed to play around with 0.6.3 and get thumbnails AND post excerpts to work. Here are all the edits I made:
Changes to 0.6.3 for Post Thumbnails
================
recently_popular.php
Uncomment lines 302, 303, 304, 315
Changes to 0.6.3 for Post Excerpts
================
recently_popular.php
Add after line 267:
`p`.`post_excerpt` AS `post_excerpt`,
Add after what was line 315:
$loutput = str_replace(‘%post_excerpt%’, $post->post_excerpt, $loutput);
Changes to 0.6.3 for Post Categories
================
recently_popular.php
Add after what was line 315:
$categories = (array) get_the_category();
$loutput = str_replace(‘%cat_name%’, $categories[0]->slug, $loutput);
You can check out the working version on my site if you need to see it in context, but those were the only edits I made.
The last one for categories doesn’t quite work as I had hoped — I use it in the other “Recent” tab on my site to style and color code posts based on the category, and it works there. With this plugin, however, it only takes the category of the first entry and applies the same styling to all entries. Still, better than nothing.
BTW, I use a manual implementation. Based on the above edits, here’s what I use on the front end:
<?php if(function_exists('get_recently_popular')) {
get_recently_popular(3, 'DAY', 8, 0, 2, '
%post_title%
%post_excerpt%
‘);
} ?>
@Everyone:
I have a new trunk release out for testing that has a number of fixes. Check out the details here:
http://eric.biven.us/2011/05/31/recently-popular-0-7-now-in-trunk/
Hi,
I have an error when installing 0.7:
Fatal error: Class ‘RecentlyPopularWidget’ not found in …/blog/wp-content/plugins/recently-popular/recently-popular-widget.php on line 10
Best regards,
Dirk Adamsky
What version of PHP are you using?
Have same problem, when I trying to activate 0.7 version geting Fatal error: Class ‘RecentlyPopularWidget’ not found in /var/www/vhosts/eddnet.org/http/wp-content/plugins/recently-popular/recently-popular-widget.php on line 10
My Php version – PHP 5.2.17
Thanks for the info, I’m looking into it.
It looks like the problem might be an eAccelerator problem that they decided to leave unfixed:
http://eaccelerator.net/ticket/146
If you’re having this problem with 0.7 be sure to let me know what version of PHP and eAccelerator you’re using (or if you aren’t using eAccelerator).
I have confirmed with one user that this is an eAccelerator bug. I will try to determine if there is a workaround.
I was able to reproduce the bug on a Centos VPS (thanks Linode) and find a workaround. 0.7.1 contains this patch.
I really like this plugin and I would like to have a random post-clone or related-post-clone of it. Do you have the time?
There are lots of random and related posts plugins out there already. Are you saying you just like the style of the widget and the function calls Recently Popular uses and would like to have something that does what those plugins already do, but with user interfaces like Recently Popular?
Your plugin is an integral part of my site but I can not help you with the development financially as you do not see the use of limited clicks by i.p or cookies to be a necessary feature. I had a dude in India develop it for your plugin and I passed the code on to you to save you the work but … You said cookies were better even though i.p works fine for me.( I told you for 20 dollars the guy would do this too) You haven’t integrated this feature so every update of your plugin I have to sit there and add the code myself. What a ball breaker job that is for a non coder like me. I’m not able to do this with the latest update as the code has changed quite a bit so I gotta pay an Indian guy to update it for me.My site isn’t making any money now. How can I pay two people. I would however prefer to pay the original developer. You’re doing the work and money is going to India. Go figure. I’m sorry but as I said to you before how can anyone with a serious site allow any knuckle head who wants just to sit there and click, click, click change the view number. I like your plugin but I am very disappointed iits development especially in consideration of sucha vital feature
I’m sorry it has been painful for you when the plugin revs up. I have several users that use slightly modified versions of the plugin. Most of them just don’t upgrade.
I have had probably a dozen users like you ask for something that nobody else has asked for. I’m glad the plugin is useful, but if I integrated everything that everyone asked for the code would be unmanageable and the interface would be cluttered.
With this last release I’ve cleared all the outstanding bugs, so I will be evaluating new features to possibly put into the plugin. First I think will be some sort of results caching, but I haven’t decided.
You should add something to only show published posts. I’ve done it by replacing your first WHERE clause “1″ -> “`p`.`post_status` = ‘publish’”. I know that’s quite static, but why should I want to see unpublished or future posts?
That never came up in testing, but it was clearly an error on my part. I wonder, though, how your future unpublished posts are winding up with counts. If they don’t have counts they could never be in the results anyway.
Eric,
I have the same class ‘RecentlyPopularWidget’ not found in /var/www/vhosts/eddnet.org/http/wp-content/plugins/recently-popular/recently-popular-widget.php on line 10 But with 0.7.1
On my live site my PHP Version is 5.2.11 wp 2.7.1 I can not install.
On my test site php 5.2.9 wp 3.1.14 its ok.
Where to find on eAccelerator?
regards
Rick
Issue fixed no problem with wp-3.2 thxs
Glad to hear it Rick. I’m not sure why that would cure it since it’s a PHP error and not a WordPress error, but I’m more than willing to just go with it.
Let me know if it crops back up.
Thanks for creating this Eric. It is exactly what I am looking for.
Hi!
Why dosn’t you insert an option to the “current category” in the category filter?
Then, if the visitor is seeing a page, for exemple, show to all categories, or just desn’t show the widget.
Thanks!
Is it possible to get on my single post template “the current category most viewed posts”?
(i need it in php)
Not with this plugin.
Does this works correctly if wp super cache is activated?
Not any more now that large portions of the caching are happening with rewrites so that WP never even see the traffic.