Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I've been trying to figure this out for many, many days now. I tried to modifiy the code various times, always with the same result. I just don't get it.

I want to properly separate pingbacks and comments which I did with the following code:

<?php if ( have_comments() ) : ?>
    <h2 class="h2comments"><img src="http://zoomingjapan.com/wp-content/themes/alltuts-child/images/comments_big.png" /><?php comments_number('No Comments', '1 Comment', '% Comments' );?> <a href="#respond" class="addComment"><img src="http://zoomingjapan.com/wp-content/themes/alltuts/images/add_your_coment_ver2.png" border="0"></a></h2>

    <ul class="commentlist">
    <?php wp_list_comments(array(
  'callback'=>'mytheme_comment',
  'type'=>'comment',
)); ?>

 <div class="navigation">
  <?php paginate_comments_links(); ?> 
 </div>


    </ul>
 <?php else : // this is displayed if there are no comments so far ?>

    <?php if ('open' == $post->comment_status) : ?>
        <!-- If comments are open, but there are no comments. -->

     <?php else : // comments are closed ?>
        <!-- If comments are closed. -->
        <p class="nocomments">Comments are closed.</p>

    <?php endif; ?>
<?php endif; ?>


<?php if ( have_comments() ) : ?>


    <ul class="pingbacks"><h2>Pingbacks</h2>
<?php wp_list_comments(array(
  'callback'=>'mytheme_comment',
  'type'=>'pings',
)); ?>
    </ul>
 <?php else : // this is displayed if there are no comments so far ?>

    <?php if ('open' == $post->comment_status) : ?>
        <!-- If comments are open, but there are no comments. -->

     <?php else : // comments are closed ?>
        <!-- If comments are closed. -->
        <p class="nocomments">Comments are closed.</p>

    <?php endif; ?>
<?php endif; ?>

However, the pingbacks (well the headline and everything) still shows up even if there are no pingbacks to display.

I tried to change it to something like this:

<?php if ( have_comments() ) : ?>
        <?php if ( ! empty($comments_by_type['comment']) ) : ?>
       <h2 class="h2comments"><img src="http://zoomingjapan.com/wp-content/themes/alltuts-child/images/comments_big.png" /><?php comments_number('No Comments', '1 Comment', '% Comments' );?> <a href="#respond" class="addComment"><img src="http://zoomingjapan.com/wp-content/themes/alltuts/images/add_your_coment_ver2.png" border="0"></a></h2>


        <ul class="commentlist">
      <?php wp_list_comments('type=comment&callback=mytheme_comment'); ?>
        </ul>
        <?php endif; ?>

        <?php if ( ! empty($comments_by_type['pings']) ) : ?>
        <h2 id="pings">Trackbacks/Pingbacks</h2>

        <ul class="commentlist">
        <?php wp_list_comments('type=pings'); ?>
        </ul>
        <?php endif; ?>


 <div class="navigation">
  <?php paginate_comments_links(); ?> 
 </div>
 <?php else : // this is displayed if there are no comments so far ?>

        <?php if ('open' == $post->comment_status) : ?>
                <!-- If comments are open, but there are no comments. -->

        <?php else : // comments are closed ?>
                <!-- If comments are closed. -->
                <p class="nocomments">Comments are closed.</p>

        <?php endif; ?>
<?php endif; ?>

However, now neither pingbacks, nor comments show up unless I take out the "if empty" command. If I do, then the pingback headline shows up again even if there are no pingbacks. This is driving me crazy! Maybe it has to do with the callback function?

Here's the function I'm calling:

function mytheme_comment($comment, $args, $depth) {
   $GLOBALS['comment'] = $comment; ?>
   <li <?php comment_class('clearfix'); ?> id="li-comment-<?php comment_ID() ?>">
     <?php echo get_avatar($comment,$size='63'); ?>
     <div id="comment-<?php comment_ID(); ?>">
      <div class="comment-meta commentmetadata clearfix">
        <?php printf(__('<strong>%s</strong>'), get_comment_author_link()) ?><?php edit_comment_link(__('<img src="http://www.zoomingjapan.com/wp-content/themes/alltuts/images/edit.gif">'),'  ','') ?> <span><?php printf(__('%1$s @ %2$s'), get_comment_date('Y/n/j'),  get_comment_time('G:i')) ?>
      </span>
  <div class="text">
          <?php comment_text() ?>
      </div>
      </div>



      <?php if ($comment->comment_approved == '0') : ?>
         <em class="comment-awaiting-moderation"><?php _e('Your comment is awaiting moderation.') ?></em>
         <br />
      <?php endif; ?>

      <div class="reply">
         <?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
      </div>
     </div>
<?php }

[Here's] a sample page of my website with comments and pingbacks.1

Please, help me figure this out. Thanks so much!

share|improve this question

1 Answer 1

up vote 0 down vote accepted

Actually, after trying a lot more I figured out that it was actually something quite simple I just forgot.

Apart from the code in the comment.php, you also have to change this in your single.php:

<?php comments_template(); ?>

to

<?php comments_template('', true); ?>

And that did the trick!

I leave this here for future reference for others who might have run into the same problem.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.