Most Recent Comments! Without Any Plugin

We use plugin/widget for show most recent comments. But we can do that with a simple code. This code gives you simple recent comments feature without plugin. also with gravatar support. Paste this code into your theme where you want. All done!

Here is the 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 code shows 5 recent comment. If you change “5” in line two, you can display more comment or less…


Related posts:

If you enjoyed this post, make sure you subscribe to my RSS Feed
Comments are closed.
Highslide for Wordpress Plugin