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”).
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_fieldis set, and change the value there if you wish.
- You can omit users from the listing by setting the function variable
$exlude_from_listingto 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”
- Download the file get-commenters.zip and unzip it into your /wp-content/plugins/ directory.
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.
- Activate the plugin from your WordPress admin ‘Plugins’ page.
- 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’)
- Add a call to the function to your template (see examples below).
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’
<ul> <?php c2c_get_commenters('top', 3); ?> </ul>
<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:
Recent love from: <?php c2c_get_commenters('recent', 3, '', ', ', true); ?>
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:
- 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_exclusionsargument to ‘false’ (default is ‘true’); changed the default
$identity_fieldvalue to ‘comment_author_email'; changed the internal exclusion variable name from
- 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 (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.