[Resolved] separate pingbacks from comments

Home Forums Support [Resolved] separate pingbacks from comments

Home Forums Support separate pingbacks from comments

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #114890
    Achim

    Hi Tom,

    I’d like to separate pingbacks from comments on post pages. Right now pingbacks are listed at the bottom of comment list. I’d like to have the headline „PINGBACKS“ just before pingbacks will be listed.

    The order should be like this

    headline „COMMENTS“
    comment-list
    headline „PINGBACKS“
    pingpack-list

    Any help is welcome
    Best’

    #115086
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Doing this would require a custom comments.php file in your child theme.

    Here’s an example of one: https://tommcfarlin.com/separate-comments-and-pingbacks/

    So you would put that comments.php file into your child theme, and it will overwrite the theme’s comments.php file.

    Let me know if you have any trouble 🙂

    #115112
    Achim

    Thank you. I did follow the instructions of the example but it didn’t work. I replaced the comments.php and put the two other php files in the same folder. The result is that only both h3 headlines are being displayed including the number of comments. No comments, no pingbacks and no number of pingbacks are being displayed.

    Any idea what to do?

    #115369
    Tom
    Lead Developer
    Lead Developer

    Hmm, this is pretty tough.

    Give this comments.php file a try: https://gist.github.com/generatepress/4b1cf22a773cdc0f06c5

    #115642
    Achim

    This is great! Works fine.
    Thanks a lot Tom.

    Best’

    #115647
    Tom
    Lead Developer
    Lead Developer

    No problem 🙂

    #115897
    Achim

    One more thing…

    I want to have the pingback h3 headline only been shown if there are pingbacks. I tried this one but it doesn’t work
    if ( ! empty($comments_by_type[‘pings’]) ) :

    How do I check for if the are pingbacks?

    #115900
    Tom
    Lead Developer
    Lead Developer

    Hmm, good question..

    You can try adding a function like this:

    function generate_post_has( $type, $post_id ) {
    
          $comments = get_comments('status=approve&type=' . $type . '&post_id=' . $post_id );
          $comments = separate_comments( $comments );
    
          return 0 < count( $comments[ $type ] );
    
    }

    Then use this conditional around your trackback heading:

    if ( generate_post_has( 'pings', $post->ID ) ) { 
    ?>
          <h3>Pingbacks and Trackbacks</h3>
    <?php
    }
    #115903
    Achim

    excellent!

    Thank you Tom

    #115942
    Tom
    Lead Developer
    Lead Developer

    You’re welcome 🙂

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.