Title: recent comments from all blogs
Last modified: August 20, 2016

---

# recent comments from all blogs

 *  [ThorHammer](https://wordpress.org/support/users/thorhammer/)
 * (@thorhammer)
 * [13 years, 9 months ago](https://wordpress.org/support/topic/recent-comments-from-all-blogs/)
 * On my “mother blog” I hope to show the last ten comments from all my multisite
   blog owners, just date, short comment excerpt and link to the commented post.
   
   To complicate: I want a comment feed like this for comments on all posts from
   category A displayed in one sidebar. And a comment feed like this for comments
   on all posts from category B displayed in another sidebar. (My blog owners are
   forced to post in either category A or B). I know this means that I have to hardcode
   the actual side bars on the mother site theme, that’s fine, but I really need
   some help on this one. Anyone? Please?

Viewing 1 replies (of 1 total)

 *  Thread Starter [ThorHammer](https://wordpress.org/support/users/thorhammer/)
 * (@thorhammer)
 * [13 years, 9 months ago](https://wordpress.org/support/topic/recent-comments-from-all-blogs/#post-3248473)
 * Ok, I have code capable of doing this, but I don’t know how to limit the comments
   to a category, and if I am using this code in two instances it might be a heavy
   load on the server. Here is the code (so far):
 *     ```
       <?php>
   
       $sqlstr = '';
       $blog_list = get_blog_list( 0, 'all' );
       $sqlstr = "SELECT 1 as blog_id, comment_date, comment_id, comment_post_id, comment_content, comment_date_gmt, comment_author, comment_author_email from ".$table_prefix ."comments where comment_approved = 1 ";
       $uni = '';
       foreach ($blog_list AS $blog) {
           $uni = ' union ';
           $sqlstr .= $uni . " SELECT ".$blog['blog_id']." as blog_id, comment_date, comment_id, comment_post_id, comment_content, comment_date_gmt, comment_author, comment_author_email   from ".$table_prefix .$blog['blog_id']."_comments where comment_approved = 1 ";
       }
       $limit = '20';
       $limit = ' LIMIT 0, '. (int)$wgt_count;
       $sqlstr .= " ORDER BY comment_date_gmt desc " . $limit;
       $comm_list = $wpdb->get_results($sqlstr, ARRAY_A);
       ?>
   
       <!--the output before styling-->
   
       <ul>
       <?php
       $count = 0;
       foreach((array)$comm_list as $comment):
         $count++;
         if($count == $number+1) break;
         ?>
         <li>
          <?php echo get_avatar($comment->comment_author_email, 32); ?>
          <a href="<?php echo get_blog_permalink($comment->blog_id, $comment->comment_post_ID); ?>" title="commented on <?php echo strip_tags($comment->post_title); ?>">
          <?php echo $comment->comment_author; ?> wrote:
          <?php echo convert_smilies(wp_trim_excerpt($comment->comment_content)); ?>
          (<?php echo human_time_diff(strtotime("{$comment->comment_date_gmt}")); ?>)
          </a>
         </li>
       <?php
       endforeach;
       ?>
       </ul>
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘recent comments from all blogs’ is closed to new replies.

## Tags

 * [category](https://wordpress.org/support/topic-tag/category/)

 * In: [Networking WordPress](https://wordpress.org/support/forum/multisite/)
 * 1 reply
 * 1 participant
 * Last reply from: [ThorHammer](https://wordpress.org/support/users/thorhammer/)
 * Last activity: [13 years, 9 months ago](https://wordpress.org/support/topic/recent-comments-from-all-blogs/#post-3248473)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
