WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
share|improve this question
up vote 1 down vote accepted

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);

share|improve this answer
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 '11 at 23:43
and the most important it how I get the results into widget area? – Radek Feb 23 '11 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 '11 at 0:03
wow, thank you for that. I will try ... – Radek Feb 24 '11 at 1:32
You can always come back and ask if you get stack – Bainternet Feb 24 '11 at 9:06

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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