Separate Pings/Trackbacks from Total Comment Count in WordPress


After taking a look at some search results and at Matt Martz’ article, Separating Pings from Comments in WordPress 2.7, I still had some issues with particularly the comment count. There were also a problem with how the functions I have added/modified are being carried across in my templates (but probably are mostly in the scope of this Blueprint theme). The files that we’re mostly going to deal with are these ones: comments.php, functions.php and single.php.

Anyways, I just want to note here how I took care of them and what I ended up with.

First and foremost, in my functions.php file, I added the following to only count comments and not the pings/trackbacks:

comment_type == ""){
            $comment_count++;
        }
    }
    return $comment_count;
} ?>

Also in functions.php, the following function is to simplify the listing of pings/trackbacks later on (used in comments.php):


    
  • In single.php, I have the snippet of code near my post’s header. I am going to display “Comment” if there are no comments and have it linked to #respond for them to leave one if they would like to. If there are comments, I display the respective linked text.

    Comment';
        }
        if ( get_comments_number() == 1 ) {
            echo '1 Comment';
        }
        if ( get_comments_number() > 1 ) {
            echo '' . get_comments_number() . ' Comments';
        }
    } ?>

    I used the above snippet as we can’t use the function comments_popup_link() in this page.

    Meanwhile, in the comments.php file, I have the following block to display comments & pings/trackbacks separately:

    
          
            

    ping_status) { ?>Trackback Address

    Trackbacks/Pingbacks

    comment_status) : // If comments are open, but there are no comments. else : // comments are closed ?>

    Comments are closed.