Disclaimer: This plugin is no longer maintained. Feel free to take what there is under the GPL and do anything you want with it.
Well, I finally think my first WP plugin is stable enough to be released to the public :), after a couple of months of testing. To my knowledge there are no bugs in the current version (1.0.1), and I think I've tested it enough.
Code
<?php/*Plugin Name: Recent CommentsPlugin URI: http://blog.geoffers.uni.cc/archives/2005/06/24/recent-comments/Description: Retrieves a list of the most recent comments.Version: 1.0.1Author: Geoffrey SneddonAuthor URI: http://geoffers.uni.cc*/
function print_gwp_recent_comments ($no_post = 5, $before = '<li>', $after = '</li>'){ global $wpdb; $comments = $wpdb->get_results("SELECT `comment_ID` , `comment_post_ID` , `comment_author` FROM `$wpdb->comments` WHERE `comment_approved` = '1' ORDER BY `comment_date_gmt` DESC LIMIT 0 , $no_post"); $output = ''; if ($comments) { foreach ($comments as $comment) { $id = $comment->comment_post_ID; $output .= $before . '<a href="' . get_permalink($id) . '#comment-' . $comment->comment_ID . '">' . $comment->comment_author . '</a><br /><span class="post">(<a href="' . get_permalink($id) . '" title="Permalink: ' . htmlspecialchars(get_the_title($id)) . '">' . get_the_title($id) . '</a>)</span>' . $after . "\n"; } } echo $output;} ?>
Usage
<?php print_gwp_recent_comments(number_of_comments, 'before', 'after'); ?>
Example
<?php print_gwp_recent_comments(10, '<p>', '</p>'); ?>
Parameters
- number_of_comments
- (integer) Number of comments to display. Defaults to 5.
- before
- (string) Text to place before the title. Defaults to '<li>'.
- after
- (string) Text to place after the title. Defaults to '</li>'.