is there any way to display recent comments in a widget area

  • only for one page? = Comments that are belongs to one page.
  • comments of one category but not from admin ( or some other user )

I want to have two widget on my home page

  • 10 last comments for one page
  • 10 last comments for one category except my own comments

1 Answer 1


I don't use widgets for this as you can easily create one and use get_comments( $args ); for the most cases for example:

10 last comments by page is :

$args = array(
        'post_id' => $post_id,
        'number' => 10,
        'status' => 'approve');

$comments = get_comments($args);
foreach($comments as $comment) :
    echo($comment->comment_author . '<br />' . $comment->comment_content);

but if you are not into the coding stuff you can use Wizzart - Recent Comments plugin that does pretty much what you need.


following comment: to get 10 last comments of a category and excluding the admin comments i only know of a custom sql query to get that results, something like:

            global $wpdb;
            $cat_id = 4; //category id
            $number = 10; // number of comments to get
            $filter_admin = " AND user_ID != '1'"; //exclude admin comments or any user by id
            $comments_types = "AND ( comment_type != 'trackback' AND comment_type != 'pingback')"; // get only user comments
            $term_rel = $wpdb->term_relationships;
            $comments_filter = "JOIN (".$term_rel." JOIN ".$wpdb->term_taxonomy." ON (".$wpdb->term_taxonomy.".term_taxonomy_id=".$term_rel.".term_taxonomy_id))";
            $comments_filter .= "ON (".$wpdb->comments.".comment_post_ID=".$term_rel.".object_ID)";
            $comments_filter .= "WHERE ".$wpdb->term_taxonomy.".term_id=".$cat_id." AND ".$wpdb->term_taxonomy.".taxonomy='category' ";
            $comments_filter .= $comments_types;
            $query = "SELECT * FROM $wpdb->comments "; 
            $query .= $comments_filter; 
            $query .= " AND comment_approved='1'$filter_admin";
            $query .= "ORDER BY comment_date DESC LIMIT $number"; 
            $comments = $wpdb->get_results($query);

  • actually I'd prefer to code it by myself ... so post_id is my page id but how I can specify category?
    – Radek
    Feb 23, 2011 at 23:43
  • and the most important it how I get the results into widget area?
    – Radek
    Feb 23, 2011 at 23:51
  • @Radek - look at the code i added and to create a widget look at codex.wordpress.org/Widgets_API#Developing_Widgets
    – Bainternet
    Feb 24, 2011 at 0:03
  • You can always come back and ask if you get stack
    – Bainternet
    Feb 24, 2011 at 9:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.