ArticlesForumDownload AboutContact

boakes.org

nice of you to drop by. tea?

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
MostWanted - a Popular Posts Plugin for WordPress

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.

The MostWanted plugin in use.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

  1. Download this fileDownload this file
  2. Rename it mostwanted.php and copy it to your /wp-content/plugins folder.
  3. 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:

  1. $top_n
    the number of results to list default = 5
  2. $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
  3. $showviews
    true if the number of times each post has been viewed should be included in the list.
    default = false
  4. $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
  5. $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)
  6. $pre
    this is a text string that is added to every line.
    default = <li>
  7. $post
    this is a text string that is added to every line.
    default = </li>
  8. $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
  9. $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
  10. $timeout
    adjusts how long the most-wanted information is cached for before being replenished from the db. A value of 0 (zero) will result in fresh data being retrieved for every query, whereas a value of 3600 will 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:

207 Responses to “MostWanted - a Popular Posts Plugin for WordPress”

Pages: «15678910111213141521»

  1. 91
    Trackback from: ButlerBlog » Blog Archive » Most Wanted Plugin
  2. 92
    Richard Silverstein Says:

    To just list the top 5 posts seems a bit limited. I’d love to see a plugin that lists, say, the top 25 or 50 posts. When you have 900 posts, including that many posts in the list is meaningful.

  3. 93
    Rich Says:

    Hi Richard, the Usage section in the main article above mentions the $top_n parameter which controls precisely the behaviour you describe - all you have to do is specify how many posts you’d like to see.

  4. 94
    Vince Anido Says:

    Hey Rich,

    Thanks so much for this plugin. It’s really great. One thing though - I’ve noticed that my stattraq queries are REALLY slow. Is there anyway to get Most-Wanted to cache it’s results, and only update it self once a day (or something)?

    I’m taking a look at some caching plugins, but haven’t had any luck getting them to work.

    -Vince

  5. 95
    Rich Says:

    Hi Vince, for this site I use wp-cache which caches every page that is accessible by your readers. This has the effect of making the site (in general) feel a lot faster. What this won’t do is speed up your stattraq-specific page access time (because stattraq lives under the wp-admin path, which is set to be uncached by wp-cache). You might also want to check out this minor modification which also helps by designating strtraq updates as a background operation.

  6. 96
    Mike Smith Says:

    Rich,

    I noticed that the article names in the most wanted list are being curtailed even when the curtail parameter is set to zero. Looking at the code could I suggest the curtail function should be ammended as follows:

    function curtail($trim_this, $trim_chars=0) {
    if ($trim_chars > 0 && strlen($trim_this) > $trim_chars) {
    return substr($trim_this,0,($trim_chars-3)) . “…”;
    }
    return $trim_this;
    }

    Mike.

  7. 97
    Rich Says:

    Thanks Mike, I’ve rolled that into MostWanted v0.1.6 which is now available for download.

  8. 98
    Scott Says:

    Well, I was hoping to not have to ask any questions, but it looks like I’m getting errors again.

    Specifically, this error:

    Warning: ob_start(): output handler ‘ob_gzhandler’ cannot be used after ‘URL-Rewriter’ in /xxxxxxxx/wp-includes/functions.php on line 585

    I had applied the FixStats.php file last night and I thought that corrected my initial error (which by the way, was the exact same error). But after adding a new post tonight, it seems the error has returned.

    Ideas or fixes? I have seen the “Michelle Fix” but have not implemented as of yet, because my permalink structure is not the same as hers. I haven’t had time to tweak the code and try to make it work with my structure (year/month/day).

    Is there something else I can do to get the plugin to work correctly? I do like it, but if it doesn’t work with permalinks, I dont know how long I’ll leave it on the site.

  9. 99
    Scott Says:

    Okay…very odd.

    My previous comment (which for some reason is showing as a reply rather then a new comment itself…but thats another issue) seems to be no longer valid.

    That initial error showed up after I posted a new entry on my site. But I then ventured to another post and back to the main page, and the problem appears to have “disappeared.” The error is no longer on the homepage.

    Any ideas why the error would show up for the initial posting, but then disappear after a simple page refresh?

    A second new posting does not repeat the error…odd.

    Thoughts in general?

  10. 100
    Rich Says:

    Hi Scott, as far as I can tell the ob_start problem is not related to MostWanted or StatTraq: I’m seeing it intermittently on your blog too, so this may help. Hmmm… on reflection… the fact that it appears when I first arrive on a page, but then not afterwards, suggests it is related to StatTraq which uses “session_start();” so the fix is even more likely to work.

    Also, I’m fairly sure that Michelle’s code fix will work for you, without alteration, because of the way the .htaccess url rewriting extracts the variables (YMD) that Michelle’s code uses.

    Have a great thanksgiving, and don’t spend too much time hacking!

    P.S. Thanks for pointing out the “looks like a reply” issue; it was down to the CSS doing too much wrapping. I’ve improved the theme and it looks to have solved it.

Pages: «15678910111213141521»