WordPress has already provided you the Recent Comment by widget setting but it has no picture gravatar. Today I’m working on it, this tutorial will show you all what I’ve done.
![]()
1. Browse to you theme folder. Open “Sidebar.php” then put this code.
<div>
<h2>Recent Comments</h2>
<ul>
<ul><!--?php <br ?--> $comments = get_comments('number=5');</ul>
</ul>
<ul>
<ul>foreach($comments as $comm) :$url = '</ul>
</ul>
<a title="'.$comm->comment_author .' | '.get_the_title($comm->comment_post_ID).'" href="'. get_permalink($comm->comment_post_ID).'#comment-'.$comm->comment_ID .'">' . $comm->comment_author . '</a>
<ul>
<ul>';</ul>
</ul>
<ul>
<ul>?>
<li><!--?php echo get_avatar($comm--->comment_author_email, 30); ?></li>
</ul>
</ul>
</div>
2. Open “style.css” then put the following selector to manage displaying style.
<div>
<h2>Recent Comments</h2>
<ul>
<?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>
</div>
3. Upload “sidebar.php” and “style.css” to your hosting. Go through Admin page > Settings > Discussion then select your prefer type of Avatar. Finished, here is what I’ve got.
