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: «123456789101121»

  1. 41
    Steve Says:

    MICHELLE YOU GODDESS!!! This works PEREFECTLY!
    Thankyouthankyouthankyou.

  2. 42
    Garnet Says:

    When I activate mostwanted I get this error in WP 1.5.1

    Warning: Cannot modify header information - headers already sent by (output started at /hsphere/local/home/dhthomas/glitteringstew.com/muse/wp-content/plugins/rjb_mostwanted.php:116) in /hsphere/local/home/dhthomas/glitteringstew.com/muse/wp-admin/admin.php on line 10

    But the mostwanted info. at least appears in the sidebar, though with no stats because I just installed it.

    David

  3. 43
    Garnet Says:

    Hey, I tried running the fixstat script and I get this error
    Fatal error: Call to undefined function: fixstats() in /hsphere/local/home/dhthomas/glitteringstew.com/muse/wp-stattraq/fixstats.php on line 4

    I placed it in the wp-stattraq folder.

    Also, when I activate the mostwanted plugin in wp-admin I get this error

    Warning: Cannot modify header information - headers already sent by (output started at /hsphere/local/home/dhthomas/glitteringstew.com/muse/wp-content/plugins/rjb_mostwanted.php:116) in /hsphere/local/home/dhthomas/glitteringstew.com/muse/wp-admin/admin.php on line 10

    Please advise. I’m not sure what is going wrong.
    David

  4. 44
    Garnet Says:

    I managed to get the statfix to run, but the links to the MostWanted list of posts still uses the post number, with a strange path, index.php?p=77, not the permalink. (I changed the index.php-normal to index.php, but no change in the link effectiveness)

    I changed the code for post ID as suggested by Rich above, I even added the snippet of code suggested by Michelle, since I use the date in the permalink.

    Any suggestions? Maybe I just need to wait for the new release of stattraq.
    David
    Sorry for so many comments.

  5. 45
    Garnet Says:

    Infinite apologies, especially to rich. I got it. my blog is in a subdirectory, so I had to change the path from /index.php to /sub/index.php

    All is well. please ignore those messages above.

    Thank you for a fine plugin of a plugin. Now someone should invent a plugin for your plugin of a plugin.

    cheers,
    D

  6. 46
    Garnet Says:

    I still can’t get the plugin to play nice with the admin headers. The plugin works on my blog, but shuts down admin, and the error code above is what I get, and later, a similar warning about wp-includes/plugable.php malfunction, again with headers.

    I really like this plugin and I hope I can figure out what is not clicking. Thanks for any input. David

  7. 47
    Darryl Says:

    Hey, you might want to consider letting the mostwanted plugin filter out bots.

    $output = $wpdb->get_results( “SELECT p.post_title, st.article_id, COUNT( DISTINCT (st.session_id) ) as cnt FROM $tablestattraq st,
    $tableposts p where p.ID=st.article_id and st.user_agent_type=’0′ GROUP BY st.article_id ORDER BY cnt DESC LIMIT 0,$top_n” );

    The key point being user_agent_type = ‘0′

  8. 48
    Darryl Says:

    Also as an idea it’s a quick and easy change to your function to limit the results to ‘x’ days (which i like :)

    $output = $wpdb->get_results( “SELECT p.post_title, st.article_id, COUNT( DISTINCT (st.session_id) ) as cnt FROM $tablestattraq st, $tableposts p where p.ID=st.article_id AND st.user_agent_type=’0′ AND DATE_SUB(CURDATE(),INTERVAL $interval DAY) < st.access_time GROUP BY st.article_id ORDER BY cnt DESC LIMIT 0,$top_n” )

  9. 49
    rich boakes Says:

    Thanks for the suggestions Darryl, I’ll incorporate both in a 0.0.8 release.

  10. 50
    Rodney Shupe Says:

    I hope you implement the sugestion above to use get_permalink on line 75 I implemented it on my install and it works great:
    "’ href=’" . get_permalink($line->article_id) . "’>"

Pages: «123456789101121»