Tags: Releases, WordPress
MostWanted - a Popular Posts Plugin for WordPress
November 24th, 2004, by Rich.
Warning: apache_lookup_uri() [function.apache-lookup-uri]: Unable to include '/pics/2005/mostwanted/mostwanted' - error finding URI in /home/www/boakes.org/htdocs/mods/plugins/boakes-depicticon.php on line 65
This WordPress Plugin which lists the most popular posts in a blog, according to the records held by StatTraq…
MostWanted lists the most popular posts on a wordpress powered weblog. This list can be used in the sidebar to provided visitors with an indication of what are the most visited pages.
It’s grown a little since it’s original release so it has a subtle API change. Where previously it was called “rjb_mostwanted”, it is now “MostWanted::mostwanted”. Currently there is a wrapper around the old method name so that it still works, however this will be removed in future releases.
Installation
Download this file- Rename it mostwanted.php and copy it to your
/wp-content/pluginsfolder. - using wp-admin, enable the plugin
Usage
The plugin provides one method of interest: MostWanted::mostwanted($top_n, $trim_chars, $showviews). The three parameters are:
$top_n
the number of results to list default = 5$curtail
0 for no text curtailment, or ‘n’ the number of characters from each post title that shoudl be displayed. e.g. Curtailing “My Dynamic Badger” to 10 characters would read “My Dyna…”.
default = no curtailment$showviews
true if the number of times each post has been viewed should be included in the list.
default = false$show_views_in_tt
TT is short for ToolTip setting this value to true includes the number of views as part of the tool tip. i.e. if you hover over the text the (1234 distinct viewers) message is shown.
default = true$duration
restricts the duration of the query period so that only the last $duration days are considered when measuring popularity. e.g. a value of 30 would return the number of users only within the last 30 days. Leaving the value unset, or 0, results in the all-time results being returned.
default = 0 (all-time)$pre
this is a text string that is added to every line.
default = <li>$post
this is a text string that is added to every line.
default = </li>$method
there are two ways of identifying unique visitors, neither of which are perfect, the default is to recognize only unique IP addresses, which means that if several people from one company visit, then they may show as a single user. Alternatively, using the session_id is not perfect because some users refuse to set cookies.
default = ip, alternative = session$as_percentage
if set to true, then the number of hits for each page as a percentage of the site total is displayed instead of the hit count itself. This may be desirable if you want to show popularity without letting on how many hits you get for each story.
default = false$timeout
adjusts how long the most-wanted information is cached for before being replenished from the db. A value of0(zero) will result in fresh data being retrieved for every query, whereas a value of3600will only query the database once every hour, cacheing the output and thus reducing DB load.
default = 1800
The simplest way to use the plugin is therefore to augment your page with:
<ul>
<?php MostWanted::mostwanted(); ?>
</ul>
A more tuned version might read:
<ul>
<?php MostWanted::mostwanted(7, 30, true); ?>
</ul>
License
MostWanted is released under a Creative Commons License.
Credits
If you find MostWanted useful, please feel free to link or a trackback to this entry.
Thanks to everyone whose commented with problems, solutions & suggestions, especially:
- Ben Gracewood whose previous suggestion here gave me enough of a head start that I was able to come up with the relevant SQL query.
- Randy Peterman
- Darryll Van Dorp
- Michelle Li
- Rodney Shupe
- Mike Smith


November 24th, 2005 at 6:31 pm
Ohhh, I always love replies that point out information that should actually help fix a problem!
From the info you gave me and after doing a quick search of the Wordpress support forums, it just looks like a WP issue itself, so not related to the plugin. Well, maybe to the StatTraq plugin, but not the MostWanted one ;)
Thanks again for the info. I’ll try out the code fix and if that doesn’t work, then I’ll give Michelle’s code a try.
December 1st, 2005 at 4:59 am
Hey Rich, I’ve been meaning to drop by with a quick reply for the past few days. Regarding the gzip compression error in Wordpress and the WeblogTools.com fix, it works, but doesn’t sort of.
If you put the fix:
php_flag session.use_trans_sid off
In the index.php code as suggested, it has no effect. It does not work and this has been confirmed by multiple users on multiple themes.
If you put it in your .htaccess file, it seems to break the newest version of Wordpress. At least it does for me.
BUT!
If you create and place the code in a file named, “php.ini”, and place it in your blog’s root directory, then it will work.
So again for anyone else with this problem - create a new file called “php.ini” and have that in your blogs root directory. In the newly created php.ini file, put in the following(minus the quotes): “php_flag session.use_trans_sid off”
Save/upload the file and you should be set!
December 16th, 2005 at 10:00 am
Hi, I’m using WP 1.5.2, MostWanted 0.1.8 (according to the PHP file), and StatTraq 1.0a. I’ve run the configuration fixstats, I’ve inserted Michelle’s code and I’ve modified lines 25 and 26 in the StatTraq php file to read:
if (($post->ID != ‘’)){
$p = intval($post->ID);
However, I’m still getting the “no results available” message. I’m using permalinks in the form of:
http://DOMAIN/blog/index.php/yyyy/mm/dd/slug/
Any other clues? You can see my “Most Wanted” links at the top of my blog, beneath the header logo.
Regards,
Rich
BlogRodent
December 19th, 2005 at 3:48 am
Any chance you can create a “most emailed” version of this plugin to work with skippy’s subscribe2 plugin?
December 23rd, 2005 at 9:35 am
RichT,
From what I can see of Michelle’s code, there doesn’t appear to be a reason for changing lines 25+26 as well. Have you tried using it without that alteration?
December 23rd, 2005 at 9:39 am
Tommy, a nice idea which I’d not considered (because i’m not using Skippy’s plugin) so if you (or anyone else) would like to submit a patch I’ll include it. The solution would just need a different SQL query.
December 23rd, 2005 at 4:08 pm
I’ve got a couple of sites that use MostWanted, and have run into Dan’s problem with the PHP error “cannot be called statically”. Checking out the PHP 5 manual (this is only a PHP 5 problem) I found this:
http://us2.php.net/manual/en/language.functions.php#44189
Since this is obviously an architecture issue and not a simple bug-fix, is there any chance of getting an update for us sad-sacks stuck with PHP 5 on our hosts?
December 26th, 2005 at 8:45 am
I’ve maybe found a bug:
I want to have both a listing for both last 30-days and all-time in my sidebar.
I use the code:
Popular Posts: last 30 days
‘,”,ip,false,0); ?>
Popular Posts: all-time
‘,”,ip,false,0); ?>
when I have them this way it does not work correctly, i.e. the all-time list is identical to the 30-day list.
when switching the order of the function calls, first with duration=0 and then with duration=30 it works OK…
January 5th, 2006 at 10:58 am
finally the same prob Chris Frazier has described.
at first I didn´t get the plugin to work at all because of the browser-issue. The whole sourcecode turned up to be shown on the plugins-page. i fixed that.
then i ran into the header-issue. fixed that.
afterwards i ran fixstats.
now i got the “cannot be called statically”-prob. i tried to understand the php5-manual-workaround but didn´t manage to.
as php5 should not be that exotic in the wild i´d have thought that Rich would already have presented a solution… Sadly i was wrong.
January 5th, 2006 at 11:28 am
I think I’m flattered that you expect so much of me :) (but please note that I’m not a software development company, I’m just a bloke that is making the things he writes for himself available to others free of charge).
I don’t have a server with PHP5 and I don’t have much free time, but I will be looking into it. If I can work out a fix I will publish it, if anyone else works it out, please submit it and I’ll make it available.