WordPress.org

Ready to get started?Download WordPress

Forums

Aggregating Recent Posts to Parent Site. Comments are off on aggregated posts. (18 posts)

  1. sspice313
    Member
    Posted 3 years ago #

    Is there a way to show the number of comments or "Add a comment" like it shows on the child blog?

    This only happens on the Parent blog.

  2. David Sader
    Member
    Posted 3 years ago #

    Aggregating with wordpress-mu-sitewide-tags?
    Then, ...

    http://wordpress.org/support/topic/forcing-comments-to-the-main-blog

    Add to theme(functions.php) of the parent blog:

    function ds_sitewide_tags_get_comments_num($count) {
      global $blog_id, $wpdb, $post;
      	$tags_blog_id = get_site_option( 'tags_blog_id' );
      	if( !$tags_blog_id || $blog_id != $tags_blog_id ) return $count;
      	list( $post_blog_id, $post_id ) = explode( '.', $post->guid );
      	$base = $wpdb->get_blog_prefix( $post_blog_id );
      	$r = $wpdb->get_col( "SELECT comment_count FROM {$base}posts WHERE ID=$post_id" );
     	if( is_array( $r ) ) return $r[0] + $count;
      return $count;
    }
    add_filter('get_comments_number', 'ds_sitewide_tags_get_comments_num');
  3. sspice313
    Member
    Posted 3 years ago #

    Hi David,

    Thank you so much for the response. I added this function to my function.php and it still isn't working. Yes i am aggregating with wordpress-mu-sitewide-tags. Is the comment Indexer required if I just want the count? As I understood on the other post it was to be used if I needed to display the actual comments on the main blog.

    Is there something else that I am missing?

  4. David Sader
    Member
    Posted 3 years ago #

    I added this function to my function.php and it still isn't working

    function.php or functions.php of your active theme?

    That snippet is an exact copy 'n paste of what is in my main blog theme's functions.php. It depends only on the sitewide tags plugin to be active and aggregating posts on that blog.

    Typically my list of posts on the front page will look like

    Title | Author | Date | from Site | Comments (2)
    Title | Author | Date | from Site | Comments (12)
    Title | Author | Date | from Site | Comments (0)
    Title | Author | Date | from Site | Comments (8)
    ...

    and if this snippet isn't there

    Title | Author | Date | from Site | Comments (0)
    Title | Author | Date | from Site | Comments (0)
    Title | Author | Date | from Site | Comments (0)
    Title | Author | Date | from Site | Comments (0)
    ...

    Also, in my theme's home.php my comments link looks like this in this posts loop:

    <a href="<?php comments_link(); ?>">Comments (<?php comments_number('0', '1', '%'); ?>)</a>

    Clicking on the comments link on the main blog takes reader to the originating post on the original site. The count shows (0) whether comments are open or closed.

    Comment Template Tags I used:
    http://codex.wordpress.org/Function_Reference/comments_link
    http://codex.wordpress.org/Function_Reference/comments_number

    Comment Template Tags I didn't use:
    http://codex.wordpress.org/Function_Reference/comments_popup_link
    Why? Because comments_popup_link shows "Comments are off for this post" if the post merely requires users to be logged in to comment - the predominant preference for my network (I didn't want every post in the loop also querying a blog option checking for comment_registration).

  5. sspice313
    Member
    Posted 3 years ago #

    function.php or functions.php of your active theme?

    I typed incorrectly. It is functions.php.

    Also, in my theme's home.php my comments link looks like this in this posts loop:

    <a href="<?php comments_link(); ?>">Comments (<?php comments_number('0', '1', '%'); ?>)</a>

    My loop.php was using "comments_popup_link".

    <span class="comments-link"><?php comments_popup_link( __( 'Add a Comment', 'twentyten' ), __( '1 Comment', 'twentyten' ), __( '% Comments', 'twentyten' ) ); ?></span>

    I tried changing it to:
    <span class="comments-link"><?php comments_link(); ?>">Comments (<?php comments_number('0', '1', '%'); ?>)</span>

    I checked to make sure that get_comments_link() was in my comment-template.php and it is.

    But I still see "Comments off" on the main blog.

  6. David Sader
    Member
    Posted 3 years ago #

    But I still see "Comments off" on the main blog.

    Make sure you are swapping all(3) of the occurrences of comments_popup_link in the twentyten loop index. If you are still seeing "Comments off" then you haven't swapped in the comments_link snippet in all the right places yet.

    Also, what I have:
    <a href="<?php comments_link(); ?>">Comments (<?php comments_number('0', '1', '%'); ?>)</a>

    becomes this for twentyten:
    <span class="comments-link"><a href="<?php comments_link(); ?>">Comments (<?php comments_number('0', '1', '%'); ?>)</a></span>

  7. sspice313
    Member
    Posted 3 years ago #

    David,

    Oh shoot! Thanks. :)

    It's working! Again thank you for helping me with this.

    The only issue now is...I see the "0 Comments" on the main blog, even though there are comments on the actual entry.

  8. sspice313
    Member
    Posted 3 years ago #

    Hi, does anyone have any ideas?

    The only issue now is...I see the "0 Comments" on the main blog, even though there are comments on the actual entry.

  9. sspice313
    Member
    Posted 3 years ago #

    In the post that you referenced you did the following:

    I use a comment indexer(in mu-plugins) that dupes every comment in the network into its own site_comments table: http://pastebin.com/DDvbJFDb

    Is this maybe the piece that I am missing? Would I need to do this for the count to be accurate? If so, where do I add the code for the comment indexer? Is it a plugin?

  10. David Sader
    Member
    Posted 3 years ago #

    comment indexer doesn't fix the comment count, but it is part of a method to get the actual comments from throughout the network to list on a main page.

    Other than what I have already posted above, which as I say works for me, I don't now w hat else to tell ya.

  11. sspice313
    Member
    Posted 3 years ago #

    Ok where do I put the code for the comment indexer? Is that a plugin file?

  12. sspice313
    Member
    Posted 3 years ago #

    Nevermind. I see that it's a plugin.

    Thanks.

  13. sspice313
    Member
    Posted 3 years ago #

    I am using the Disqus plugin. It looks like the comment number value is being pulled from the Disqus comment count as 0. Has anyone come across this issue while using Disqus? I am wondering if that is why it isn't working with David's solution.

  14. @David I'm actually running through testing this now. The newer version of SWT actually closes comments on entries it pulls. :-/

    any ideas? other than editing that bit out of the plugin?

  15. David Sader
    Member
    Posted 3 years ago #

    @Andrea_r 0.4.0.1 of Sitewide Tags Pages plugin is what I have. Looked in trac, I don't see a newer version.

    closes comments on entries it pulls

    Agreed, when I edit a duped post in the tags blog(main blog in my case), indeed the discussion checkboxes are unchecked, closed, while in the original post they are checked and open. But the code I have pasted above still generates a correct comment count on the front page post loop nonetheless. The side effect for me is that I see "Comments (n)"(where n is usually 0) instead of "Comments off" if indeed the original post has comments closed.

    The key is the comments_number and comments_link template tags I use in the loop of my home.php:
    <a href="<?php comments_link(); ?>">Comments (<?php comments_number('0', '1', '%'); ?>)</a>
    rather than the more traditional comments_popup_link
    <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?>
    or
    <?php comments_popup_link( __( 'Leave a comment', 'twentyten' ), __( '1 Comment', 'twentyten' ), __( '% Comments', 'twentyten' ) ); ?>

  16. Okee dokee - thanks for checking. My eyes were crossing by then.

    *lightbulb* on changing the comments link.

  17. sspice313
    Member
    Posted 3 years ago #

    @Andrea_r does this mean that you got it to work correctly with Disqus?

  18. No. I was trying to get it to work just with regular comments.

Topic Closed

This topic has been closed to new replies.

About this Topic