[resolved] Comment count - only works on single.php but not on index.php (11 posts)

  1. do77
    Posted 4 years ago #


    I tried retrieving the comment count (I am using Facebook Comments for WordPress) for each post so I included
    <?php comments_number('no responses','one response','% responses'); ?>
    into my code. If I include it into the single.php it works fine and shows the correct number of comments posted. However, if I add the code snippet to the index.php (within the loop) it only says 'Leave comment' and does not show the number of comments already posted.

    Any idea why that is?

    Many thanks to all!

  2. Rev. Voodoo
    Volunteer Moderator
    Posted 4 years ago #

    does your index.php show your comments template, or just a link and you want it to display comment numbers?

    If the second, use comments_popup_link


  3. do77
    Posted 4 years ago #

    The index.php does not show the comments template. I basically have a link below each post either saying 'Leave comment' or displaying the number of comments (well, that's at least my goal).

    I just tried it with the comments_popup_link but it still does not work. It only says 'Leave comment' but does not show the count :(

  4. do77
    Posted 4 years ago #

    Could the reason be my comments.php file? Because the WP comments would show up below the 'facebook comments' after installing the plugin I deleted most of what is in the comments.php file.

    This is what is left:

     * @package WordPress
     * @subpackage Default_Theme
    // Do not delete these lines
    	if (!empty($_SERVER['SCRIPT_FILENAME']) && 'comments.php' == basename($_SERVER['SCRIPT_FILENAME']))
    		die ('Please do not load this page directly. Thanks!');
    	if ( post_password_required() ) { ?>
    		<p class="nocomments"><?php _e("This post is password protected. Enter the password to view comments.", ''); ?></p>

    Anything wrong with that?

  5. eugenealegiojo
    Posted 4 years ago #

    Similar post here: http://wordpress.org/support/topic/plugin-facebook-comments-for-wordpress-comment-count-not-calculating?replies=2

    No response yet. Still waiting for the fix. New version still has some bugs.

  6. Rev. Voodoo
    Volunteer Moderator
    Posted 4 years ago #

    Apologies, I didn't realize the plugin affected things differently, I can't answer the question as I don't use that plugin at all....

  7. eugenealegiojo
    Posted 4 years ago #

    After debugging and tracing the plugin codes, I fixed it. I just need to remove a line of condition ($fbc_options['displayPagesOrPosts'] == 'posts') && (!is_single()) around line 27 in facebook-comments-combinecomments.php file (that's for 3.0.2 version).

    For version 2.1.2 or lower, you can find it in facebook-comments-functions.php around line 173.

    Hope this helps.

  8. do77
    Posted 4 years ago #

    Perfect! That worked for me as well. Thanks so much eugenealegiojo!

  9. kivieg
    Posted 4 years ago #

    I am using 3.1.3 and not getting any accurate count (always zero) on either the index.php or the single.php.

    If it's any clue, I have a one other bug: the option to "Check the Post comment to my Facebook profile box by default" seems to have no effect (the option is always checked).

    Any idea if I'm doing something wrong or if this is just buggy?


  10. alexistkd
    Posted 4 years ago #

    i have issue too i dont see comments count just No comments yet.

    heres is code of facebook-comments-combinecomments.php

    } elseif (!comments_open() ||
    			  ($fbc_options['displayPagesOrPosts'] == 'pages') && (!is_page()) ||
     ($fbc_options['displayPagesOrPosts'] == 'posts') && (!is_single())) {
    			 	  return $wpCommentCount;
    	} else {

    but if i erase the line ($fbc_options['displayPagesOrPosts'] == 'posts') && (!is_single())) i get blank page.

    thanks in advance.

  11. Taipa
    Posted 3 years ago #

    eugenealegiojo's fix no longer seems to work for 3.1.3, so post counts on the index page are all screwed up and displaying the same # for each post, regardless of how many comments that post has.

Topic Closed

This topic has been closed to new replies.

About this Topic