Recent Comments Without Plugins

Sep 27, 2009

Here’s a very simple PHP script to make WordPress regurgitate some recent comments without installing any plugins … good for doing something very specific within a template or a footer. Within the foreach statement, you can print the array items however you want (list, div, br, etc.). The get_comments() function has a handful of parameters that can restrict the comments retrieved. As opposed to messing around with the wp_list_comments() to make it display correctly, I prefer to do this.

I’ve only listed the array items that I think are typically important, but there are a few more available; there’s a full list of them here.

<?php
	$comments = get_comments();

	foreach($comments as $comment) :

		if ($comment->comment_approved == 1) : 

			echo $comment->comment_ID;
			echo $comment->comment_post_ID;
			echo $comment->comment_author;
			echo $comment->comment_author_email;
			echo $comment->comment_author_url;
			echo $comment->comment_date;
			echo $comment->comment_content;

		endif;

	endforeach;
?>
Keighl

© 2010 Keighl

1.508.265.3032
info@keighl.com