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


January 5th, 2006 at 12:07 pm
thanx for replying at the speed of light.
looking into the php5-manual it seems that this could be just a tiny thing to be changed. i would if i could, but unfortunately…..
and besides: happy new year!
January 14th, 2006 at 8:34 pm
Hi, I’d like to use your plugin and it basically works. But as soon as I activate it, the special German characters ä ö ü etc get gobbled up in the entire blog! Any clue on that?
January 15th, 2006 at 1:38 am
I downloaded the PHP file, renamed it, installed it on my Wordpress setup and under the plugins section it displays the source of the file instead of the actual plugin listing! I opened up the file and was suprised to find a bunch of HTML tags mixed with php, is this correct? I tried downloading with my browser and with CURL and WGET and they all returned the same file. So what am I doing wrong? Thanks,
–
Matt
January 17th, 2006 at 1:11 am
Hi Rich,
You need to provide a link to get a non-HTMLised version of that file, otherwise it’s a real nightmare to get a working version!
cheers,
Chris
February 2nd, 2006 at 2:27 am
Hi Rich: i just activated the plugin and I get the following message in my sidebar:
WordPress database error: [Table 'studyabroad.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,10
Any Ideas? This is a wordpress install running on Windows IIS if that matters?
You may see it in the sidebar here: http://www.cadc.auburn.edu/soa/studyabroad/
I will keep it up for a bit in case you get time to check it out - thanks in advance.
February 2nd, 2006 at 8:55 pm
I get the same as this
I downloaded the PHP file, renamed it, installed it on my Wordpress setup and under the plugins section it displays the source of the file instead of the actual plugin listing! I opened up the file and was suprised to find a bunch of HTML tags mixed with php, is this correct? I tried downloading with my browser and with CURL and WGET and they all returned the same file. So what am I doing wrong? Thanks,
February 13th, 2006 at 1:11 am
February 14th, 2006 at 7:02 pm
yup, just installed it, all i get is the source code filling the page…
February 14th, 2006 at 7:08 pm
i reckon the authors web server is html-ising all the .phps files. so none of them will work for anybody, just tried downloading an earlier version and got the same problem…
February 15th, 2006 at 4:22 pm
Argh! Thanks for spotting that Ben. It seems someone’s installed a filter at a lower level then wordpress and it’s automatically html-izing the php script on the way through. I’m chaining the main download to a ZIP file now.