Plugin: Top/Recent Commenters

Name:
Top/Recent Commenters
Author:
Scott Reilly
Version:
1.0
Last updated:
24 March 2005
Download:
Description:

Retrieve the top commenters or most recent commenters to your site (if called outside “the loop”) or for a particular post (if called inside “the loop”).

Notes:

After having just yesterday released a Recent Commenters plugin, I’ve deprecated it and rolled it into this new plugin since Top Commenters functionality only requires slight changes to the code for the previous plugin. And rather than maintain two slightly different plugins, I merged them.

This plugin outputs a list of the N top commenting visitors (with their total comments count) or the most recently commenting authors (with hyperlinks to their homepage if they provided an URL). You can define $before and $after text/HTML to bookend each list item. Specify $num_people to control how many people to list.

  • You can infer the unique identity for your commenters in one of three ways, based on the name they provided, email, or url. By default, this plugin assumes it is based on ‘comment_author_email’. Other options are ‘comment_author_name’ and ‘comment_author_url’. Look at the code for the function for where $identity_field is set, and change the value there if you wish.
  • You can omit users from the listing by setting the function variable $exlude_from_listing to a value appropriate to the $identity_field, such that if you have:

    $identity_field = 'comment_author_email';


    Then you would exclude a person by doing:

    $exclude_from_listing = array('[email protected]');


    Or exclude a set of people:

    $exclude_from_listing = array('[email protected]', '[email protected]');

  • You can also configure whether you want the generated links to the commenter’s sites should be opened in a new window or not:

    $open_in_new_window = false;

  • Can be used inside or outside “the loop”
Installation:
  1. Download the file get-commenters.zip and unzip it into your /wp-content/plugins/ directory.
    -OR-
    Copy and paste the the code ( get-commenters.phps ) into a file called get-commenters.php, and put that file into your /wp-content/plugins/ directory.
  2. Activate the plugin from your WordPress admin ‘Plugins’ page.
  3. Optional: Look at the code for the 3 configuration options you can change —
    a.) You can determine a unique visitor in one of three ways (by name, email, or url); default is email
    b.) If you want to exclude certain people from the listings, you can list them
    c.) You can set whether links to visitor sites open in a new browser window (default is ‘false’)
  4. Add a call to the function to your template (see examples below).
Functions:
[I’ve defined the $num_posts arg as 2 for all of the examples in order to limit the amount of sample output.]

function c2c_get_commenters($type='top', $num_people=5, $before='<li>', $after='</li>', $omit_last_after=false, $do_exclusions=true)

  • $type : Either ‘top’ (to get top commenters) or ‘recent’ (to get recent commenters); default is ‘top’
  • $num_people : The number of recent commenters to be returned; default is 5
  • $before : The text to display before each recent commenter.
  • $after : The text/HTML to display after each recent commenter.
  • $omit_last_after : Boolean value (either ‘true’ or ‘false’) indicating if the $after text should be omitted from the last listed item; default is ‘false’
  • $do_exclusions : Boolean value (either ‘true’ or ‘false’) indicating if the list of people to be excluded (a setting configured within the function itself) should be used; default is ‘true’
Tips & Examples:

1.) Example:

<ul> <?php c2c_get_commenters('top', 3); ?> </ul>

Outputs:

<ul> <li><a href="http://www.joebob.org" title="Visit Joe Bob's site">Joe Bob</a> (75)</li> <li>No Homepage Guy (56)</li> <li><a href="http://www.suzy.org" title="Visit Suzy's site">Suzy</a> (41)</li> </ul>

Which looks like:

2.) Example:

Recent love from: <?php c2c_get_commenters('recent', 3, '', ', ', true); ?>

Outputs:

Recent love from: <a href="http://www.joebob.org" title="Visit Joe Bob's site">Joe Bob</a>, No Homepage Guy, <a href="http://www.suzy.org" title="Visit Suzy's site">Suzy</a>

Which looks like:

Recent love from: Joe Bob, No Homepage Guy, Suzy

Release Log:
  • 24 Mar 2005 : v1.0 —
    • Verified to work for WP 1.5 (still also works for WP 1.2)
    • Fixed bug where “target=” would appear for commenters who did not have URLs
    • Renamed function from get_commenters() to c2c_get_commenters()
    • Moved WP 1.2 compatibility check outside of the primary function.
    • Updated license and examples
  • 06 Dec 2004 : v0.93 — Slight tweak to allow plugin to function in WP1.3+
  • 09 Jul 2004 : v0.92 — Can now define a list of people to exclude from the listings; the exclusion list now applies to both ‘recent’ and ‘top'; the exclusions can be turned of by setting the new $do_exclusions argument to ‘false’ (default is ‘true’); changed the default $identity_field value to ‘comment_author_email'; changed the internal exclusion variable name from $omit_this_identity to $exclude_from_listing
  • 09 Jul 2004 : v0.91 — Fixed bugs reported by kristin at the WordPress Forum. Thanks, kristin!
  • 08 Jul 2004 : v0.9 — Released to the public
Copyright & Disclaimer:

Copyright (c) 2004-2005 by Scott Reilly (aka coffee2code)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIESOF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Acknowledgements:
I’d like to thank Nick Momrik since I used his Recent Comments and Recent Posts plugins as the initial inspiration for original versions of this plugin.

87 thoughts on “Plugin: Top/Recent Commenters

  1. Great plugin.
    Althuogh I’ve a problem. If a kommenter use special or country dependent characters (like áö?? in Hungary) then after the spec character the commenter’s name disappears. For example: if the commenter “Dúalon”, then plugin comes with “D.” as the name.

    Do you have any idea?
    Thanks.

    csikszem

  2. Hi, I’m having the same issue described by Valerie in comment #26 above… it will only display commenter names and stats from the oldest post displayed on the main page. I tried the fix you recommended in comment #27 above, but I don’t have the code you say to look for in the index.php file of the site it is installed on ( using WordPress 2.0.5). Are you planning on fixing this in an upcoming release? I hope so, it’s a great plugin otherwise.

  3. I should add that the site I installed the plugin on has two sidebars, one on either side of the main content area. The above is only true when I put the code in the sidebar that comes after the loop, on the right. When I put it in the left sidebar, it works fine.

  4. Great plugin! But depending on where I put the code… it doesn’t show. It works on some places in my sidebar.php, but not anywhere. And it doesn’t work at all in my page.php template. I don’t get an error code… it just doesn’t show.

    What’s the problem? How do I get it to show in my page template?

  5. The plugin works fine with WP 2.1.2. Initially I had issues using it in the sidebar as others have reported. I also couldn’t find the snippet of code referenced in #27 so I just picked a spot and added the code to index.php and the plugin worked perfectly. I only added “” – not the other code. Thank you for the plugin.

  6. Very nice plugin. I been “googleing” for days trying to find a plugin like this only including posts made by authors at our site. I short, we would like to make a “top commenters and authors list”, since authors can make both new post and comments to existing post. Is is somehow possible to change the plugin to make this happend?

  7. Dear Scott,

    Thanks for such a wonderful plugin but i am not able to make it work on my website can you please have a look at it.

    Thanks in advance,
    Samir.

  8. I love these comment plugins as they give website owners a bit of love for leaving comments rather than treating webmasters as spammers just for leaving a worthwhile comment.

    Also these comments will not just bring in comments but it will bring lots of readers as well as these plugins tend to attract many people with little promotion.

Comments are closed.