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


April 22nd, 2006 at 7:26 am
April 22nd, 2006 at 12:46 pm
Aha - instead of calling MostWanted::mostwanted(); this seems to (mostly) work:
the odd thing I get now is that although the widget is configured to only show the top 5 I actually get the top 5 repeated twice..
Go figure! :-)
cheers, Chris
May 12th, 2006 at 10:09 pm
May 13th, 2006 at 11:31 am
May 15th, 2006 at 5:44 pm
Ok, I have taken a look at the mostwanted plugin code, since a site i am managing for one of our customers uses the plugin and I see a big load on the database caused by this plugin.
Now, I see some form of caching is implemented, but i don’t see how this caching carries over to different processes. Is the $cached_result stored in the database somewhere? I’m probably gonna patch this thing up myself to do proper caching, but of course not if it has already been solved.
May 27th, 2006 at 12:24 am
I get this:
WordPress database error: [Table '******.st' doesn't exist]
SELECT COUNT( * ) as cnt FROM st where st.user_agent_type=’0′
Warning: Division by zero in …
May 27th, 2006 at 10:02 am
Hi Lauren, initially this looks like a “no stattraq” problem. Is stattraq installed? Also, which version of wordpress are you using?
May 27th, 2006 at 4:31 pm
I installed StatTraq, but there’s an error with that, my comment on StatTraq’s site isn’t even approved yet, though. That error said that I have no auth.php in my admin folder.
I HATE 2.0, so I use 1.5.2.
THANKS!
May 27th, 2006 at 4:58 pm
Aha, this may be a 1.5 compatibility issue.
BTW If it’s just the 2.0 editor you don’t like, it can be turned off, permanently - I did so and 2.x is great :)
May 28th, 2006 at 1:36 am
Actually, when it’s turned off, uploading images is still horrible. I do have the plugin Iimage Browser for some blogs, which would work, then. And I have it for this blog. But there’s also that blue and the hiding menus every time I’m logged out. I don’t know. What do you think?
I see there’s an apparent unofficial version, I think I’ll try that for now.