Get Recent Comment with Gravatar without plugin


Sponsored Links






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

Subscribe to Full RSS Feed

RSS FeedIf you thing this article useful, please consider subscribing to our RSS Feed or e-mail updates and stay updated with us. You can also follow @WPTricksNet on twitter for latest updates.

About WP Tricks

We are WordPress Family, we collected and writed useful tips and tricks for you WordPress. We share it for you...

Related Tips and Trick from Local Data and on The Net

Download Gravatar Widget Plugin

I love and really enjoy Gravatar, we can simply display our avatar or photos in our site and of course on WordPress. Download Gravatar Widget plugin for WordPress. This plugin is the easiest ways to diplay our gravatar on our … Read More

How To Automatically Refuse Comment without Plugin

For many year Spam is the big enemy on internet, there are so many way to Automatically Refuse Comment, some tricks need installed some plugin such as Akismet, WP-Spamfree, Bad Behavior and many more, But I will show you how … Read More

How To Load Gravatar on the Fly

Gravatar become very popular image recognition, it's small image displayed almost on my WordPress Themes. After acquired by Automattic, Gravatar seamless integrated in WordPress.com. And for WordPress.org users, there are some ways to displayed on th

The Right Way to Change The Default Gravatar in WordPress

I will show you How to Change the Default Gravatar in WordPress, why? Because one of my favourite WordPress Comment enhancement is added Gravatar, after Gravatar become Automattic Family, Gravatar become more and more better. Especially integrated wi

How To Create Popular Post without Plugin

Today WP Tricks is how to create popular post without any plugin. We need to run little bit query using some code and place this code on whatever you want to put on. Example we can put this code on … Read More

How To Display Recently Registered Users on WordPress

With little bit functions Display Recently Registered Users on WordPress with Gravatar is easy, we only need to write down little bit of code and the result will be displayed. This code is original resource from WP Recipes, we only … Read More

Get Recent Comment with Gravatar without plugin / WordPress Tricks

Daily The Best WordPress Tricks and WordPress Tips to make your WordPress nice read more

Source: http://wptricks.net/get-recent-comment-with-gravatar-without-plugin/

Gravatar - Globally Recognized Avatars

Gravatar A Globally Recognized Avatar. Your Gravatar is an image that follows you from site to site appearing beside your name when you do things like comment or post read more

Source: http://en.gravatar.com/

How To Create Popular Post without Plugin / WordPress Tricks & Tips

Get Recent Comment with Gravatar without plugin. Many WordPress User need to display Recent Comment on the sidebar or footer with Gravatar, most of them using plugin, right read more

Source: http://wptricks.net/how-to-create-popular-post-without-plugin/

Display recent comments with gravatar and excerpts? - WordPress

I couldn't seem to find a plugin with as $comment) { $post_obj = get_post($comment and just found out it has its own Recent comments widget but without gravatar. read more

Source: http://wordpress.stackexchange.com/questions/6581/display-recent-comments-with-gravatar-and-excerpts

How To Get and/or Add A Gravatar To Your Post Comments | Blogging

How to get or create an avatar. How to register an avatar with Gravatar.com. How to add avatars to your comment Get Recent Comments Plugin | Blogging Without A Blog read more

Source: http://bloggingwithoutablog.com/how-to-get-andor-add-a-gravatar-to-your-post-comments/


44 Responses to Get Recent Comment with Gravatar without plugin

  1. Pingback: designfloat.com

  2. nug says:

    oke thanks for trick i will try it on my blog :D

  3. Pingback: Cara Bikin Recent Comment Tanpa Plugin / ID-JAUHARI

  4. Pingback: Free WordPress Theme: Gunungkidul / WordPress Themes, Plugins & Development

  5. lily says:

    thanks so much, I will applecate it.

  6. catering says:

    thanks so much, I will applecate it.

  7. mike says:

    Can someone help me I don’t know how to limit comment lenght. I’m using the second code (the one that’s easier)

  8. Pingback: Sélection de fonctionnalités WordPress sans plugins | Blog de Johan BLEUZEN

  9. Without plugin… wow its really great..
    I added this code..
    thanks.

  10. Lavisto says:

    It’s great since we can do this w/o a plugin.
    I’ll on my site. Thanks :-)

  11. 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

  12. Ri says:

    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.

  13. Pingback: WordPress: Kommentare ohne Plugin mit Avatar anzeigen » Plugin, Kommentaren, Codeschnipsel, Suche, Dementsprechend, Avatare » QuerBlog.de

  14. Chris says:

    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.

  15. label says:

    I have to try this right away, thank you so much for sharing, that was exactly what I was looking for!

  16. 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?

  17. andyrio says:

    My Q,did we must add a new CSS file to make this work? Sorry i;m new with wp.

  18. Vishu says:

    thanks a lot! much appreciated..

  19. Guru Talks says:

    I like the second one with css.

  20. Andrew says:

    How can we use this to show only an excerp of the comment?

  21. The second one in CSS is alot better. Thank you for sharing.

  22. Matt says:

    Hello,

    This is great thank you.

    It’s tips and hints like this that have fully endeared me to the WP community!

    Thanks,
    Matt

  23. It’s great to do stuff without plug-ins. It is very easy to add a lot of unnecessary bloat to your website by installing a lot of plugins.

  24. John says:

    Thanks for the tips. I’d like to use the second one on my site, but I need to show the relative time of the comment too (eg, 5 minutes ago, etc) Is that possible? I’ve actually been trying to do it all day, but nothing works :(

  25. Jürgen says:

    A great tutorial which I will implement. Very easy to understand. I will applecate it.

  26. John says:

    Thanks for great post, for sure i will use it in my work
    Thanks again

  27. Mr.Lu says:

    Thanks so much, i’ll share to my community.

  28. Mishelli says:

    Is there any specific reason why plugin shouldn’t be used? Is there any specific advantage why the code posted above should be used instead?

  29. Sagive says:

    neat code man :)
    10x gona use it

  30. Chris says:

    so how do you get the comment excerpt instead of full comment with the 2nd code example?

  31. pRistasiana says:

    Without plugin… wow its really great..
    I added this code..
    thanks. :)

  32. andra says:

    Very nice scipt, yesterday I trying this script, very useful. Thank’s

  33. duyhen says:

    i want to display same your site, where do i put code into sidebar

  34. duyhen says:

    into end sidebar.php, display same your site not, display content

  35. duyhen says:

    thanks, i done it, but how to want to abstract comment?

  36. Pingback: How To Automatically Refuse Comment without Plugin | WordPress News Wire

  37. prahalad says:

    this works g8, i was fed up with many plugins and got frustrated..this is awesome…some help i needed in this if u can…Can u tell me how to get the comment limited characters…it is displaying full comment…i want it to be limited characters..plz tell me where to change the code….

  38. Jonny says:

    For those of you that are having problems defining a custom excerpt length, I’ve got a solution for the second method!

    Add this to the first php block:
    $length = 40; // adjust to needed length
    $thiscomment = $comm->comment_content;
    if ( strlen($thiscomment) > $length ) {
    $thiscomment = substr($thiscomment,0,$length);
    $thiscomment = $thiscomment .' ...';
    }

    Then instead of using:
    echo $comm->comment_content;

    Use:
    echo $thiscomment;

    Hope this helps everyone! :)

  39. Pingback: Reading up on “comments” again « Feet up, eyes closed, head back

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>