Get the recent comments without using wordpress plugin or widget

Sponsors

You can display the most recent comments of your entire blog without any wordpress plugin.

I want to display the comments in footer area. I created following code. You can copy paste the code in your sidebar.php or footer.php file.

Using following code you are able to display recent comments with author’s gr-avatar also.


<?php
$total_comments = $wpdb->get_results("SELECT comment_date_gmt, comment_author, comment_ID, comment_post_ID, comment_author_email FROM $wpdb->comments WHERE comment_approved = '1' and comment_type != 'trackback' ORDER BY comment_date_gmt DESC LIMIT 10");
$comment_total = count($total_comments);
echo '<ul>';
for ($comments = 0; $comments < $comment_total; $comments++) {
echo "<div style='clear:both;width:355px;padding-top:3px;'><div style='float:left;width:35px;'>";
echo get_avatar($total_comments[$comments]->comment_author_email,$size='32',$default='<path_to_url>' );
echo "</div> <div style='width:320px;'>";
echo '<li>';
echo $total_comments[$comments]->comment_author . ' says ';
echo '<a href="'. get_permalink($total_comments[$comments]->comment_post_ID) . '#comment-' . $total_comments[$comments]->comment_ID . '">';
echo get_the_title($total_comments[$comments]->comment_post_ID);
echo '</a></li></div></div>';
}
echo '</ul>'
?>

My footer is looking like as follows:

Incoming search terms:

You may like following Articles!

34 thoughts on “Get the recent comments without using wordpress plugin or widget

  1. your article is very amazing ,and i want to ask you a question : in my blog ,in the author page ,i just want to show the author’ s comment list ,how should i do .

    • Just use following code
      $total_comments = $wpdb->get_results(“SELECT comment_date_gmt, comment_author, comment_ID, comment_post_ID, comment_author_email FROM $wpdb->comments WHERE comment_approved = ’1′ and comment_author=’author name’ and comment_type != ‘trackback’ ORDER BY comment_date_gmt DESC LIMIT 10″);

  2. I prefer cPanel for its ease of use, I like the fact that it’s a large, reliable and reputable company. This eases my mind about the long term potential of the product. And from my personal experience with it, it’s always worked for me and never let me down.

  3. Recently I have been seeing this recent comments on several blogs and was wondering how they were able to do that. I thought it was a plugin or module, but now I did understand the way it is done.
    Register Web Domain

  4. Nice post! You truly have a wonderful way of writing which I find captivating! I will definitely be bookmarking you and returning to your blog. In fact, your post reminded me about a strange thing that happened to me the other day. I’ll tell you about that later…

  5. HI! First of all great article!!
    I have a question though…

    In stead of showing the post the comments was made in I would like to show the actual comment from the person. How do I do that?

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>