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


May 6th, 2005 at 2:27 pm
I swapped out that portion, but still no post ID’s..everything is set as “0″. Maybe send me your whole stattraq.php file? Maybe you changed something else and forgot about it?
May 6th, 2005 at 8:50 pm
A few additional things:
- Although it is updating newer entries, when I run fixstats, it produces the identical list of 64 fixed entries every time.
- Some RSS feed hits are being ignored (set to ‘0′). I guess this is a problem for Randy, but couldn’t hurt to mention it here (and he seems to be MIA for a month now).
- I found a bug in your plugin, line 75: “‘ href=’/index-normal.php?p=” I changed that back to ‘index.php’
Requests:
- Can you add a parameter to list only the posts of given category(s)? For example,
php rjb_mostwanted(10, 30, true, 1,2);would list only the top 10 posts in categories 1 and 2.- Would it be possible to change the above line 75 to use the permalink, if the WP install is using permalinks, instead of post ID?
Thanks..
Steve
May 7th, 2005 at 8:49 pm
I’m getting an error that says maximum execution time of 30 seconds has been exceeded when running the fixstats function.
What setting do I need to change?
May 7th, 2005 at 8:52 pm
found my answer… php.ini!
May 7th, 2005 at 9:56 pm
I have one problem: my listing (mostwanted pages on sidebar) shows correct URLs for articles, but incorrect URLs for pages.
Pages have link syntax: http://www.yoursite.com/?page_id=number
and your plugin shows http://www.yoursite.com/?p=number (wrong, this is syntax for articles, not for pages).
Any help or idea?
Many thanks, Martin
May 9th, 2005 at 8:54 am
I have one problem: my listing (mostwanted pages on sidebar) shows correct URLs for articles, but incorrect URLs for pages.
Pages have link syntax: /?page_id=number
and your plugin shows /?p=number (wrong, this is syntax for articles, not for pages).
Any help or idea?
Many thanks, Martin
May 10th, 2005 at 9:22 pm
My Popular shows for ever: No results available.
But stattraq is still logging and works fine.
Wordpress 1.5, any idea?
Thanks
May 10th, 2005 at 9:23 pm
Ops I insert the wrog url the blog where this plugin doesn’t work is http://www.gotroot.it
May 15th, 2005 at 9:35 pm
Update: I’ve done a clean install of WP 1.5.1, on a completely different server, and I’m still having the problem of stattraq not recording permalinks, even with your modified code–I’m running fixstats.php every day manually :(
I’ve cross-posted over at stattraq site in hopes to solve this..I really need it to work.
May 18th, 2005 at 5:58 am
Hi I am using Wordpress 1.5 and hacked a quick solution to fix permalink storage in the database. My StatTraq now works for all permalinks. This is also specially set for permalinks using month, day, and year. Sorry if the naming is bad. I find the
post_namein the database and check against the timestamp. You can adjust it if you use other formating. I dunno why but I can’t post on the StatTraq website. Please let me know how it goes. =)instructions:
right under
$article_id = 0; // default/mixed page - not just for one article
place the following:
// BEGIN MICHELLE CODE
$myName = $_GET['name'];
$myMon = intval($_GET['monthnum']);
$myYear = $_GET['year'];
$myDay = $_GET['day'];
$mysqlQuery = “SELECT ID as pid, UNIX_TIMESTAMP(post_date) as pdate FROM wp_posts WHERE post_name=’$myName’”;
$myOutput = $wpdb->get_results($mysqlQuery);
if (isset($myOutput)) {
foreach ($myOutput as $myline) {
$sDate = getdate($myline->pdate);
$myMon2 = $sDate['mon'];
$myYear2 = $sDate['year'];
$myDay2 = $sDate['mday'];
if($myMon==$myMon2 && $myYear==$myYear2 && $myDay==$myDay2) {
$article_id = $myline->pid;
}
}
}
// END MICHELLE CODE