Top Ad unit 728 × 90

Display Most Recent Comments with Gravatars


Have you seen sites that display most recent comments in their sidebar with user gravatars. Well this can be done easily with these codes. Simply paste the following code anywhere you want to display the most recent comments.
01<?php
02$query = "SELECT * from $wpdb->comments WHERE comment_approved='1'
03ORDER BY comment_date DESC LIMIT 0 ,5";
04$comments $wpdb->get_results($query);
05
06if ($comments) {
07echo '<ul>';
08foreach ($comments as $comment) {
09$url '<a href="'. get_permalink($comment->comment_post_ID).'#comment-'.$comment->comment_ID .'" title="'.$comment->comment_author .' | '.get_the_title($comment->comment_post_ID).'">';
10echo '<li>';
11echo '<div class="img">';
12echo $url;
13echo get_avatar( $comment->comment_author_email, $img_w);
14echo '</a></div>';
15
16echo '<div class="txt">Par: ';
17echo $url;
18echo $comment->comment_author;
19echo '</a></div>';
20echo '</li>';
21}
22echo '</ul>';
23}
24?>
To get more or less than 5 comments, change the number 5 on line 2.
I see lots of tutorials about how to get the most recent comments in WordPress. Irrespective of how popular is your blog but it’s always good idea to show commenter’s gravatar in sidebar. Then what is the best way to show most recent comments on your WordPress blog with Gravatar?
Simply put below code to your theme’s file.
Let me know what you think about this.
Have a suggestion or anything to add to this article? Chime in and share as a comment.
Display Most Recent Comments with Gravatars Reviewed by Unknown on 3:45 AM Rating: 5

No comments:

All Rights Reserved by Boca Raton Real Estate © 2014 - 2015
Powered By Blogger, Designed by Sweetheme

Contact Form

Name

Email *

Message *

Powered by Blogger.