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


August 11th, 2005 at 8:23 pm
Great plugin but I’m having problems. Since I first activated your plugin, I suppose it read stats from stattraq and gave me some output. Now, it’s been over a month and a half and the stats aren’t changing. I.e. the top post according to your plugin has 7 views whereas stattraq states that my top single post is 27 views. What gives or am I just stupid? Here is the snippet I am using in my sidebar (included within php of course):
MostWanted::mostwanted(10, 120, true, true, 0, ”, ”)
August 12th, 2005 at 2:21 pm
Hi Mayur. I notice from looking at your site that you’re using permalinks. So my guess is that previously you weren’t. This would explain why the plugin worked ok for a while.
As discussed in the earlier comments, this is due to a bug in stattraq that I’m hoping (and kind of expecting) will be fixed in its next release.
In the mean time you might want to look back through the comments for suggestions of how to work around the issue - if it doesn’t solve the problem I’ll investigate further.
August 12th, 2005 at 5:06 pm
Forgive my ignorance, where do I implement the change you linked to?
August 12th, 2005 at 5:12 pm
Nevermind my previous comment, I figured out where to put it but it doesn’t work (I deactivated and activated the plugin twice). In response to your earlier comments, I have ALWAYS had permalinks and I have never turned them off. Any other ideas?
August 12th, 2005 at 6:04 pm
Hopefully this will narrow down the problem area a bit…
You can check in the stattraq table of your database to see that the fix is working. what you’re looking for is in the article_id and url fields.
SELECT url, article_id from 'wp_stattraq' where url like("%oldest%") order by line_id desc;Wherever you see a url field like:
/index.php?name=the-oldest-old-people&page=You should also see a non zero number in the article_id column, this is the post’s id, and MostWanted uses this information, looking at the source of your article I’m guessing the oldest old people article is post
#95.If you see 0 (a zero) in the article_id column when there are names in the url column, then it’s the fix that’s not working, rather than the plugin. Once we’re sure it’s the plugin I can dig deeper.
August 15th, 2005 at 4:33 am
I get the following error after activating the plugin
Parse error: parse error, unexpected T_VARIABLE in /home/heather/public_html/pro/wp-content/plugins/mostwanted.php on line 142
August 15th, 2005 at 7:52 am
Hi Heather, as a sanity check I just re-downloaded version 0.1.4 from this page and re-installed it on this site, but failed to get the error that you describe. Can you double check that you have this latest version?
August 20th, 2005 at 10:47 pm
I got it working shortly after i posted this but came up with another problem when viewing single post
WordPress database error: [Table 'jennifer_pro.st' doesn't exist]
SELECT p.post_title, st.article_id, COUNT( DISTINCT (st.ip_address) ) as cnt FROM st, wp_posts p where p.ID=st.article_id AND p.post_status=’publish’ AND st.user_agent_type=’0′ GROUP BY st.article_id ORDER BY cnt DESC LIMIT 0,5
August 22nd, 2005 at 10:10 pm
August 23rd, 2005 at 5:40 pm
Hi,
[Wordpress 1.5.1.2 + MostWanted Version: 0.1.4]
After putting
in sidebar.php
I’ve got this:
Fatal error: Non-static method MostWanted::mostwanted() cannot be called statically in /home/(…)/sidebar.php on line 25
The plugin is activated, statraq works well, so? What’s wrong?