“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.

Recently Popular Widget 0.4.7 (simple)

Recently Popular Widget 0.4.7 (simple)

Recently Popular Widget 0.4.7 (formatting options)

Recently Popular Widget 0.4.7 (formatting options)

Recently Popular Widget 0.4.7 (category options)

Recently Popular Widget 0.4.7 (category options)


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>
 
  • Share/Bookmark