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


December 27th, 2004 at 12:38 pm
January 28th, 2005 at 1:59 am
I’m getting the same error as post #4
Fresh install of Apache 2 on XP professional.
Wordpress 1.22
don’t know what I’m doing much more than that!
Warning: Invalid argument supplied for foreach() in yadayada…\wp-content\plugins\mostwanted.php on line 57
April 25th, 2005 at 3:07 pm
Hey, trying out your plugin. Is there a place to get the code without cutting and pasting ? Right now I have to go in an manuall erase all the line numbers….
April 26th, 2005 at 9:07 am
Thanks for the suggestion Darryl, there’s a quirk between IE and Firefox that I’d not noticed - IE copies only the text, whereas Firefox copies the line numbers too. I’ve added a downloadable version as requested.
April 26th, 2005 at 4:33 pm
Thanks!
May 5th, 2005 at 1:36 pm
I’m getting the invalid argument error as well, WP 1.5. Any fix for this?
Another question– is there any way to include or exclude categories? For example, I would want toshow just the top 5 hits from posts in category X and y..
May 5th, 2005 at 1:50 pm
Hi Steve, Which template page are you adding it to, on which theme?
May 5th, 2005 at 2:20 pm
Kubrick was the starting theme, but its way past resembling it anymore :)
The code is in my sidebar. See my email addy for the site.
May 5th, 2005 at 3:24 pm
I’ve just updated the plugin to 0.0.6. The changes are unlikely to affect the error, but if you can update your version then at lest your errors and my version number will be consistent.
FWIW The 0.0.6 update isn’t particularly impotant and doesn’t need upgrading to unless anyone else has a problem. It’s a formalization of the things I’ve been doing to stattraq to combat referral spam.
May 5th, 2005 at 3:51 pm
Same error:
Warning: Invalid argument supplied for foreach() in /wordpress/wp-content/plugins/mostwanted.php on line 65