WordPress.org

Ready to get started?Download WordPress

Forums

recent comments from all blogs (2 posts)

  1. ThorHammer
    Member
    Posted 1 year ago #

    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?

  2. ThorHammer
    Member
    Posted 1 year ago #

    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>

Topic Closed

This topic has been closed to new replies.

About this Topic