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 25th, 2004 at 12:02 pm
November 30th, 2004 at 4:51 pm
December 1st, 2004 at 4:05 pm
I just installed it and started clicking links to load up the stats. I can see the link hits but the first 2 most popular are not listing.
response: Ah! this is a hangover from an earlier test version. installed plugins should change the sql statment from reading “DESC LIMIT 2,$top_n” to “DESC LIMIT 0,$top_n”. I’ve updated the copy on this page.
Also “Reader Dave’s Double Wall” gets a slash added to “Reader Dave/’s Double Wall.”
response:Looks like an escaping issue - will investigate.
December 5th, 2004 at 9:22 pm
With: <?php rjb_mostwanted(10, 30, true); ?>
i receive the error:
Warning: Invalid argument supplied for foreach() in /home/html/wordpress/wp-content/ plugins/MostWanted.php on line 54can you help me please?
Thanks!
response: investigating…
update: cannot reproduce - need more info - are you using url rewriting?
December 6th, 2004 at 2:43 pm
December 7th, 2004 at 10:57 pm
I am getting the same error as comment number 4!!
December 15th, 2004 at 11:44 pm
I have WP installed 2 times on my site, in the same DB but with different tablenames, as well as stattraq plugin on both.
MostWanted plugin works, but not right. On one blog it shows what is correct, on the other it shows the wrong titles, right links though. The wrong titles are from my other blog …
Any clue? (I don’t have this on my blog, but on a separate php file not linked)
rich: possibly (hopefully) fixed by the 0.0.4 release.
Also, I did have to put a "." at line 60 before the slash to make the links go to the right folder WP is installed in for each.
such as:
"./index.php?p="Would that be messing it up?rich: That would explain the links being “right” but the titles being wrong.
December 18th, 2004 at 1:44 pm
The error referred to in post #4 seems to come from SEO use (mod_rewrite that is). I’ll look into the code to see if there’s something to be done. This looked promissing.
December 19th, 2004 at 3:07 am
IS this thing on?
response: yes it is. and in answer to your other (repeated) question, my email address should be pretty simple to guess since you know the domain name already…
December 23rd, 2004 at 6:46 pm
I’m getting a database error (table doesn’t exist) on my main page. I’m using the function in a php file in the public_html root directory rather than the /blog directory my blog is in. Am I doing something wrong?
rich: hmmm. i just took a look at your site and i can see that stattraq is working normally, so initially i’m stumped… i’ll have a root around. is everything else normal? are you running this in a page where you’ve already done:
require('wp-blog-header.php');