Plugin: Customizable Comment Listings

This plugin has been updated! Comments to this post are now closed. For the latest download, documentation, and link for posting new comments related to this plugin, visit the plugin’s new homepage at:
coffee2code.com/wp-plugins/customizable-comment-listings
Name:
Customizable Comment Listings
Author:
Scott Reilly
Version:
0.9
Last updated:
30 March 2005
Description:

Display Recent Comments, Pingbacks, and/or Trackbacks, as well as other comment listings using the comment and/or post information of your choosing in an easily customizable manner. You can narrow commentt searches by specifying post IDs, comment types, and/or comment status, among other things.

Notes:
Installation:
  1. Download the file customizable-comment-listings.zip and unzip it into your /wp-content/plugins/ directory.
    -OR-
    Copy and paste the the code ( customizable-comment-listings.phps ) into a file called customizable-comment-listings.php, and put that file into your /wp-content/plugins/ directory. Please ensure you do not introduce any spaces or other characters before the <?php or after the ?>
  2. Optional: Change configuration options in the file to your liking. In-code comments should help you there.
  3. Activate the plugin from your WordPress admin ‘Plugins’ page.
  4. Include one or more of the templates defined below into your index.php
Functions:

function c2c_get_comments ($limit = 5, $format = "", $mode = 'comments', $types = 'comment pingback trackback', $status = '1', $ids = '', $order = 'DESC', $offset = 0, $date_format = 'm/d/Y', $include_passworded_posts = false )

function c2c_get_recent_comments( $limit = 5, $format = "<li>%comment_author%: %comment_excerpt_URL%</li>", $types = 'comment pingback trackback', $status = '1', $ids = '', $order = 'DESC', $offset = 0, $date_format = 'm/d/Y', $include_passworded_posts = false )

function c2c_get_top_commenters( $limit = 5, $format = "<li>%comment_author_URL% (%total_comments%)</li>", $types = 'comment pingback trackback', $status = '1', $ids = '', $order = 'DESC', $offset = 0, $date_format = 'm/d/Y', $include_passworded_posts = false )

function c2c_get_recent_commenters( $limit = 5, $format = "<li>%comment_author%: %comment_excerpt_URL%</li>", $types = 'comment pingback trackback', $status = '1', $ids = '', $order = 'DESC', $offset = 0, $date_format = 'm/d/Y', $include_passworded_posts = false )

  • $limit : The number of comments to list/return; default is 5
  • $format : A string that uses percent substitution tags to define the data you want displayed for each listing and how you want it displayed;set it to ” (two single-quotes) to return an array of the requested comment objects without outputting anything.
  • $mode : The manner in which comments are to be considered, either ‘comments’, ‘recentcommenters’, or ‘topcommenters’
  • $types : A space-separated list of comment types to include; can be any combination of ‘comment’, ‘pingback’, and/or ‘trackback’
  • $status : A space-separated list of comment status values to include; can be any combination of ‘1’ (approved comments), ‘0’ (unapproved comments), and/or ‘spam’ (spam, obviously).
  • $ids : A space-separated list of post IDs with which to limit the search for the comment listings
  • $order : The order with which the comment listing should be sorted, either ‘ASC’ (for ascending) or ‘DESC’ (for descending); default is ‘DESC’
  • $offset : The number of comments to skip; default is 0
  • $date_format : Date format string, PHP-style, if different from the blog’s default date-format string
  • $include_passworded_posts : A boolean value, either ‘true’ or ‘false’, indicating if passworded posts should be considered in the comment search
Tips & Examples:

The simplest examples would be the following (for brevity’s sake, in the examples I’m going to specify 3 as the number of posts I want returned):

<ul>Recent Comments <?php c2c_get_recent_comments(3); ?> </ul>

Would output something like:


<ul>Recent Commenters <?php c2c_get_recent_commenters(3); ?> </ul>

Would output something like:

    Recently Commenters

  • John: Ha! That was so funny I…
  • Sarah: I’ve got a story that will…
  • Tom Jones: Haven’t you heard of the red…

<ul>Top Commenters <?php c2c_get_top_commenters(3); ?> </ul>

Would output something like:


But what you may really want is to run the Recent Comments calls and customize the listing output. That’s where the percent substitution tags come into play. The $format argument to each of the functions above is a string that represents how each commentt found by the function should be output. Any percent tags (as listed and defined above) will be replaced with the appropriate data.

So, let’s say you only want to list the most recent comment, to include the comment author’s name linked to that person’s site (if they provided an URL), plus a short excerpt of the post, plus the title of the post the comment appeared in linked to the post itself. You’d do this:

<ul> <?php c2c_get_recent_comments(1, "<li>%comment_author% said \"%comment_excerpt%\" in <br />%post_URL%</li>"); ?> </ul>

Which would output something like:

Release Log:
  • 30 Mar 2005 : v0.9 — Released to the public
Copyright & Disclaimer:

Copyright (c) 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 WARRANTIES OF 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:
N/A

82 thoughts on “Plugin: Customizable Comment Listings

  1. Pingback: Blogging Pro
  2. Great plugin.

    One problem I have with it is that I cannot manipulate the date format. If I include $date_format = 'D. j F Y' or 'D. j F Y' in the function, the comments do not show up (but no errors are thrown on the page).

  3. How exactly are you calling the function? An example of defining a custom date format:

    <?php c2c_get_recent_comments(5, "[%comment_date%] %comment_author%: %comment_excerpt_URL%", 'comment pingback trackback', '1', '', 'DESC', 0, 'D. j F Y'); ?>

    You have to define all the function arguments leading up to the one you want to change.

  4. Hey, Scott:

    Is there a way to use this *along with* Customizable Post Listings? When I try to enable it with CPL already installed, I get:

    Fatal error: Cannot redeclare c2c_comment_count() (previously declared in [snip] customizable-comment-listings.php:197) in [snip] customizable-post-listings.php on line 136

  5. Jeff: There will be. I’ve been delayed in getting the latest release of Customizable Post Listings out the door, which will (among other things) not cause this conflict, which is arising because the Customizable Comment Listings needs a function that CPL also needs. CCL checks to make sure the function wasn’t already defined, whereas CPL does yet do that check. In the menatime, you could always rename the function c2c_comment_count() in CPL to some nonsense, if you plan on having CCL also activated. CPL should be updated by the end of the weekend.

  6. Thanks! I was going to try yanking that function from CPL (since I wasn’t messing with comments in my CPL setup anyway), but it seemed excessively violent; I thought I’d ask first. ๐Ÿ˜‰

  7. I receive an undefined function error: get_comment_link() in
    $new = “$new“;

    on line 289. When I take out this string it works, but loose the linking to the comments listed. Why would it cause an error you think?

    This is the string I use in the index:

  8. How could I use this code if I wanted it on a difrent site (not running wordpress). I would like to show my last 5 updates on my friends site so……….

    Appreciate any help
    Cron

  9. Hey, why do I keep getting a “fatal error” on my webpage when I try to insert the codes into my sidebar template? It keeps saying there’s an undefined function…

    I’m doing the following on my template:

    Recent Comments
    Recent Comments

    Is there something I’m missing? I’ve uploaded the zip file and unzipped it into my wp-plug-ins directory, and it shows as activated…should I be doing something else?

    Could it be that I’m using the 3-column Kubrick? Or have I coded improperly?

  10. Hi,
    I’m trying to display the comment excerpt in the tool-tip of the link using the “a title” tag, but it only shows the first word of the string. This is how I’m calling the function:

    
    %comment_author_URL% on <a href="%comment_link%" title="%comments_excerpt%" rel="nofollow">%post_title%</a>"); ?&gt;
    

    I tried several different percent substitution tags, but each time it only shows the first word in the tool tip. If I hard code a string it shows the full string.

    Any idea what the problem could be? Thanks

  11. Hi, I installed your plug-in. Now, on my wp-admin pages, the following text appears in my headers:

    Warning: Cannot modify header information – headers already sent by (output started at /home/typeoff-de/htdocs/wp-content/plugins/customizable-post-listings.php:2) in /home/typeoff-de/htdocs/wp-admin/admin.php on line 6

    Warning: Cannot modify header information – headers already sent by (output started at /home/typeoff-de/htdocs/wp-content/plugins/customizable-post-listings.php:2) in /home/typeoff-de/htdocs/wp-admin/admin.php on line 7

    Warning: Cannot modify header information – headers already sent by (output started at /home/typeoff-de/htdocs/wp-content/plugins/customizable-post-listings.php:2) in /home/typeoff-de/htdocs/wp-admin/admin.php on line 8

    Warning: Cannot modify header information – headers already sent by (output started at /home/typeoff-de/htdocs/wp-content/plugins/customizable-post-listings.php:2) in /home/typeoff-de/htdocs/wp-admin/admin.php on line 9

    When I try to post or comment, I get similar errors as well. Do you want what I am doing wrong?

    (I’m hgoing to take the plug-in out for now, but I really like it, and would like to put it back in!)

  12. Love the plug in, used it on 3 sites I’ve put together for people… 1 question though.

    I’ve changed the $ types to ‘comment’ only as I don’t want pingbacks listed but it makes no difference, have I missed something?

  13. is it possible to reduce the number of words that is extracted from comment excerpt? it shows too many words for my liking on my sidebar. thanks for any responses!

  14. Hi, Scott. The only function I see missing from this plugin is the ability to filter comments by cat_ID. I could REALLY use most recent comments and top commentors per cat_ID.

    Any chance you’ll soon update the plugin to do this?

  15. I just want to be able to show the number of comments from a specific post.. how can I do this? I can;t figure out how to write it. I am using Customizable-comment-listing.php as well.

  16. I am trying to use the plugin, but when I unzipped the file, my WordPress blog doesn’t display anymore. Is there something wrong with the php file?

    Thanks.

  17. Pingback: ...but it's dirty!
  18. Scott, all I can say it’s a great plugin! I’m using your plugin a lot. I’m currently testing my website and it doesn’t validate xhtml transitional. Because of your plugin! lol… Since I don’t have a lot of content there is one c2c_get_recent_posts() that return nothing, because the category is empty. w3c validator says:

    
    end tag for "ul" which is not finished.
    
                      
    
    Most likely, You nested tags and closed them in the wrong order. For example <em>... is not acceptable, as <em> must be closed before . Acceptable nesting is: <em>...</em>
    
    Another possibility is that you used an element which requires a child element that you did not include. Hence the parent element is "not finished", not complete. For instance,  generally requires a , lists (ul, ol, dl) require list items (li, or dt, dd), and so on.
    

    Can you extend your code to return an empty () when the return is empty?

  19. hi. i really like this plugin. just one issue though…

    whenever i use the excerpt, be it the short or the regular for say 5 recent posts, the excerpts display the same text for different posts. Please help me with this issue.

    Is there a way that the plugin can extract random posts under a certain category number?

  20. Hello I am sorry to bother you – I really tried to figure this out. I have your plug in set for Recent Commenters. When someone who has commented on my blog before posts a new comment it shows a past comment from them not the most recent? Any ideas on what I did wrong. I have everything set for Descending. .Thank you – I really appreciate it! Fantastic plugin!

  21. How can I include this code and where ?
    Plesae Help me.
    Thanks
    4. Include one or more of the templates defined below into your index.php

    Functions:
    function c2c_get_comments ($limit = 5,
    $format = “”,
    $mode = ‘comments’,
    $types = ‘comment pingback trackback’,
    $status = ‘1’,
    $ids = ”,
    $order = ‘DESC’,
    $offset = 0,
    $date_format = ‘m/d/Y’,
    $include_passworded_posts = false )

  22. Hello I am still trying ot figure this out – I am sorry to bother you. . .I have your plug in set for Recent Commenters. When someone who has commented on my blog before posts a new comment it shows a past comment from them not the most recent? Any ideas on what I did wrong. I have everything set for Descending. .Thank you – I really appreciate it! Fantastic plugin!

  23. Hello Scott,

    This is a terrific plugin. I read in an old post that there was the possibility to include the “category” to which the post belongs. Is this possible?

    Thanks and congratulations for this beautiful piece of code.

    Diplo

  24. hi i love the plugin my ony problem is, if i try to activate it and customizable post listing, it causes wordpress to conk out. any thoughtson what causes this or how to fix?

Comments are closed.