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>';
}
?>
This tricks I got from WP Recipes, you can add some style and make it suitable for you themes.
Alternate Method Display Recent Comment
<li class="boxr therecent">
<h3>Recent Comments</h3>
<ul class="recent-comment">
<?php
$comments = get_comments('number=5');
foreach($comments as $comm) :
$url = '<a href="'. get_permalink($comm->comment_post_ID).'#comment-'.$comm->comment_ID .'" title="'.$comm->comment_author .' | '.get_the_title($comm->comment_post_ID).'">' . $comm->comment_author . '</a>';
?>
<li>
<?php echo get_avatar($comm->comment_author_email, 30); ?>
<strong><?php echo $url; ?></strong>
<p><?php echo $comm->comment_content; ?></p>
</li>
<?php
endforeach;
?>
</ul>
</li>
This code more easy to implemented and use, after you write this code, you need to open style.css ad add css code
.recent-comment li {
display: block;
border-bottom: 1px dotted #ccc;
}
.recent-comment .avatar-30 {
float: left;
margin-right: 10px;
}
And done, I hope you enjoy our Recent Comment with Gravatar without Plugin tips

oke thanks for trick i will try it on my blog
Got some problem? Please let’s me know…