Many WordPress User need to display Recent Comment on the sidebar or footer with Gravatar, most of them using plugin, right now I will show you how to Get Recent Comment with Gravatar without plugin. All need to do just write little bit of code and modified as many you want and you need.
On our recent article, I was cover tips to display most commented post with gravatar without plugin, and I hope you’ll enjoy this tricks too, because this trick also simple and of course useful.
Let’s get started, open your sidebar.php or footer.php or whatever files you need to display recent comment and add this code
<?php
$query = "SELECT * from $wpdb->comments WHERE comment_approved= '1'
ORDER BY comment_date DESC LIMIT 0 ,5";
$comments = $wpdb->get_results($query);
if ($comments) {
echo '<ul>';
foreach ($comments as $comment) {
$url = '<a href="'. get_permalink($comment->comment_post_ID).'#comment-'.$comment->comment_ID .'" title="'.$comment->comment_author .' | '.get_the_title($comment->comment_post_ID).'">';
echo '<li>';
echo '<div class="img">';
echo $url;
echo get_avatar( $comment->comment_author_email, $img_w);
echo '</a></div>';
echo '<div class="txt">Par: ';
echo $url;
echo $comment->comment_author;
echo '</a></div>';
echo '</li>';
}
echo '</ul>';
}
?>

oke thanks for trick i will try it on my blog
Got some problem? Please let’s me know…
thanks so much, I will applecate it.
thanks so much, I will applecate it.
Can someone help me I don’t know how to limit comment lenght. I’m using the second code (the one that’s easier)
Without plugin… wow its really great..
I added this code..
thanks.
It’s great since we can do this w/o a plugin.
I’ll on my site. Thanks
nice triks and i’ve been try to my bottom template but how can i change size of the gravatar image cause i’ts so big at my theme. rgds
How about instead of the comments entire content just an excerpt of it? How could I possibly do that? Thanks for this amazing code btw.
Nice snip it, but how do I make it to display comments anywhere and not just on the page that has comments?
I have this running in my footer, and it works when you land on a page with comments, but once you goto a page with no comments you see nothing accept the avatars
Hi, I got the same question as well. How can we make this code more flexible, so that it can be placed on any page and still be useful? I’d love to place these recent comments on a “non-comments” page, if you know what I mean.
I have to try this right away, thank you so much for sharing, that was exactly what I was looking for!
I have been working with the comments on my page for few days now to make it not so boring. Your tips sounds great and I’ll surely try it. Will this work regardless of the browser we are using?
My Q,did we must add a new CSS file to make this work? Sorry i;m new with wp.