How to Display Recent Comment with Gravatar – No Plugin

Posted By Peach on February 14th, 2011

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.

config the avatar type
1. Browse to you theme folder. Open “Sidebar.php” then put this code.

<h2>Recent Comments</h2>
  <ul><!--?php <br ?--> $comments = get_comments('number=5');</ul>
  <ul>foreach($comments as $comm) :$url = '</ul>

<a title="'.$comm-&gt;comment_author .' | '.get_the_title($comm-&gt;comment_post_ID).'" href="'. get_permalink($comm-&gt;comment_post_ID).'#comment-'.$comm-&gt;comment_ID .'">' . $comm-&gt;comment_author . '</a>

     <li><!--?php echo get_avatar($comm--->comment_author_email, 30); ?&gt;</li>


2. Open “style.css” then put the following selector to manage displaying style.

<h2>Recent Comments</h2>
  $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>';

     <?php echo get_avatar($comm->comment_author_email, 30); ?>
     <strong><?php echo $url; ?></strong>
     <p><?php echo $comm->comment_content; ?></p>

  <?php  endforeach;  ?>

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.
Display recent comment with Gravatar

Tags: , ,

  • Best SEO Software

    Really great subject!

  • The Best SEO Software

    Thanks for these more forward-thinking ideas.

  • Shanita

    Just where is the facebook like button ?

  • Gabrielle

    Terrific, that’s precisely what I was shooting for! Your article just spared me alot of digging around

    I’ll make certain to put this in good use!

  • design website and buidl website

    An interesting discussion is worth comment. I think that you should write more on this topic, it might not be a taboo subject but generally people are not enough to speak on such topics. To the next. Cheers

  • Internet marketing tools

    Please, can you PM me and tell me few more thinks about this, I am really fan of your blog

  • WillSmith

    ZPqbii Hi! I’m just wondering if i can get in touch with you, since you have amazing content, and i’m thinking of running a couple co- projects! email me pls

  • Dopalacze

    Date Hello, I have browsed most of your posts. This post is probably where I got the most useful information for my research. Thanks for posting, maybe we can see more on this. Are you aware of any other websites on this subject

  • Dopalacze

    I fully agree with author opinion.

  • Rental Yacht

    I love the blog site layout ! How did you make it!? It is very cool!

  • charter yacht caribbean

    A cool post right there mate ! Cheers for the post .

  • barricas

    No specific criteria and I don’t take it too seriously. I just score em’ like the magazines do.

  • binh nguyen

     Please, translate code from WordPress to Blogger! sent rerult to mail:

  • free cougar dating

    Great thanks for the share , This what I;m looking for my blog !!