Forums

[resolved] How do I NOT count number of trackbacks/pingbacks with comments_number? (9 posts)

  1. elanaspantry
    Member
    Posted 1 year ago #

    Since we hide trackbacks/pingbacks, we also don't want them counted when using the comments_number function. For instance, if we have a post that has 8 comments and 1 pingback, we want the comments_number output to be 8 comments (instead of 9).

    Here's an example post: http://www.elanaspantry.com/cooked-veggies/how-to-roast-a-pumpkin-in-10-steps/

    Is this possible?

    Thanks!

  2. elanaspantry
    Member
    Posted 1 year ago #

    No one knows the answer to this?

  3. wp_guy
    Member
    Posted 1 year ago #

    It's a little complicated, but can be done.

    You have to add this bit of code to the 'functions.php' file of your theme: (preferably at the end, before the '?>')

    add_filter('get_comments_number', 'comment_count', 0);
    function comment_count( $count ) {
    	global $id;
    	$comments = get_approved_comments($id);
    	$comment_count = 0;
    	foreach($comments as $comment){
    		if($comment->comment_type == ""){
    			$comment_count++;
    		}
    	}
    	return $comment_count;
    }

    If the functions.php file doesn't exist, create it.

  4. elanaspantry
    Member
    Posted 1 year ago #

    thx for your reply wp_guy...

    i created a file called functions.php, inserted the code above and uploaded it to my themes directory.

    no luck though. it still counts the pingbacks:

    http://www.elanaspantry.com/desserts/chocolate-orange-truffles/

    this is what the code looks like for displaying comments on single.php:
    comments_number('0 comments','1 comment','% comments');
    and comments.php:
    comments_number('no comments', '1 comment', '% comments' );

    any thoughts?

  5. elanaspantry
    Member
    Posted 1 year ago #

    i did forget to mention that i was using the Separate Comments & Pings Plugin - this seems to be confusing WP.

    i disabled that and of course the numbers are correct now - but the pingback shows up in the comments (which is what we don't want)

    thanks again...

  6. wp_guy
    Member
    Posted 1 year ago #

    Weird, because that plugin is supposed to adjust the comments number.

    Could it be that you are using an older version of the plugin?

  7. elanaspantry
    Member
    Posted 1 year ago #

    nope - using version 1.0 (the current version)

    i disabled the plugin for now...

  8. elanaspantry
    Member
    Posted 1 year ago #

    OK - i decided to search for a better plugin with support: http://wordpress.org/extend/plugins/comment-sorter/.

    I installed it, set it up and it appears to work fine. Thanks for your efforts again wp_guy.

  9. jloayza
    Member
    Posted 4 months ago #

    @wp_guy: It worked like a charm. Thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic