Home » , , , » How to display most recent comments with Gravatar

How to display most recent comments with Gravatar

You can show your recent comments in your blog sidebar or anywhere with this trick. This will display recent comments with their gravatars. 
How to Do ??

  • Copy this code and Paste code anywhere on your theme files.

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

  • Now It will show most recent 5 comments on your blog. To change the no. of recent comments, Change the number 5 on line 2
  • Done
If You Like product from here Click Here free product informationGoogle Android PC Tablet

0 comments:

Post a Comment

 
Support : Creating Website | SEO Template | Free Template
Copyright © 2011. Free Wordpress Theme And Templates For You - All Rights Reserved
Proudly powered by Blogger