Display most recent comments with Gravatar

In order to display the 5 most recent comments with their gravatars, paste this code anywhere on your theme files. To get more or less than 5 comments, change the number 5 on line 2.

<?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>’;
}
?>

Looking for WordPress hosting? Try WP Web Host. Prices starts at $5/month and you can try it for free!Display most recent comments with Gravatar

You Might Also Like...

  • WordPress hack: Get popular posts by comments count

    2642 readersIn blogging, it is useful to be able to display your most popular posts. There's WordPress plugins to do that, but you don't need it: This code will display your most popular posts, accordoing to the comments count, without requiring you to use a plugin.Looking for WordPress hosting? Try WP Web Host. Prices starts at

  • WordPress hack: Remove admin name in comments class

    2616 readersBy default, when the blog admin left a comment on his blog, WordPress use the name in the comment css class. This is useful for styling, but it will also let people know about your admin login name. If you want to hide this info, read this recipe.Looking for WordPress hosting? Try WP Web Host.

  • MySQL DB

    Quick Tip: “Popular Posts By Comment Count” SQL Query in WordPress

    2450 readersYou might have noticed that the Tuts+ sites have a section on the home page where we list the most popular posts of the month, according to comment count. While there are numerous plugins available, it’s always best to write the code yourself if you can. Too much abstraction is never a good thing! Luckily,

  • Display Gravatar & Autofill Fields for Previous Commenter

    772 readersWhen someone comments on your site, cookies with the information the entered are saved to their computers. WordPress makes it easy to access that information. In fact, in your comments.php template they are ready-to-go PHP variables you can spit out anywhere you’d like. Let’s take a look. Here are the most important ones, when it comes

  • How to Create a Comments Central Page Template in WordPress

    295 readersOne way to increase visitor engagements is to reward their comments by showcasing them on your website. Additionally, you can also feature the top commenters as well, linking back to their website in the process. Here we’ll create a dedicated Page Template to display those comments and commenters in one place. In short, this tutorial

  • WordPress hack: Insert comments programatically

    2732 readersSome time ago, I've shown you how to insert posts programatically in WordPress database. So now, what about comments? In this recipe I'll show you Looking for WordPress hosting? Try WP Web Host. Prices starts at $5/month and you can try it for free!WordPress hack: Insert comments programatically

  • How To: Displaying Your Most Commented Posts

    170 readersThough this isn’t quite the same as displaying your most popular posts in your sidebar, here is some code you can use to display the posts that have received the most comments.  You’ll want to place it in your sidebar where you want the code to be displayed. Most Commented Posts Code Go into your theme files

  • Optimise Your WordPress Themes With Better Author Pages

    1885 readersRecently Ajay D’Souza asked how we made our author archive pages here on BloggingPro. I personally am a big fan of displaying content differently on different sections of blogs and also think that archives should be more informative than be just a collection of excerpts. Because I personally believe that an ‘Author Information’ block below every

  • How to display Twitter-like “time ago” on your WordPress blog

    1511 readersTwitter have a really cool built-in function that display time from now, like "3 days ago" or "more than a month ago". Doing so with WordPress is not hard using some PHP. Here is a function to do so.Looking for WordPress hosting? Try WP Web Host. Prices starts at $5/month and you can try it

  • ;)

    WordPress hack: Show your top contributors without a plugin

    2231 readersDo you ever wished to be able to list your top contributors without using a plugin? If yes, you'll be happy with this recipe that will show you how to do it. Looking for WordPress hosting? Try WP Web Host. Prices starts at $5/month and you can try it for free!WordPress hack: Show your top