admin管理员组

文章数量:1122846

I'm building a comments template using wp_list_comments(); and comment_form(); — I'm doing it this way because I want to use different containers depending on whether to not there are already comments on the post.

Here's the whole thing:

<?php 
 // Hide on password protected 
 if(post_password_required()) {
  return;
 }
 $comment_count = get_comments_number();
 if($comment_count > 0): 
?>

 <div class="ca alt" id="comments"> 
  <div class="width">
   <h2 class="comments-title">
   <?php
    printf( _nx( 'Comments on &ldquo;%2$s&rdquo; (1)', 'Comments on &ldquo;%2$s&rdquo; (%1$s)', get_comments_number(), 'comments title' ),
    number_format_i18n( get_comments_number() ), get_the_title() );
   ?>
   </h2>
   <?php 
    wp_list_comments(array(
     'style'            => 'div',
     'type'         => 'comment',
     'max_depth'    => 3,
     'per_page' => 12,
    ));
   ?>
  </div> <!-- /width -->
 </div> <!-- /ca -->
 <div class="ca" id="comment-form">
  <div class="width">
   <?php comment_form(); ?>
  </div> <!-- /width -->
 </div> <!-- /ca -->

<?php else: ?>

 <div class="ca alt" id="comment-form">
  <div class="width">
   <?php comment_form(); ?>
  </div> <!-- /width -->
 </div> <!-- /ca -->

<?php endif; ?>

My problem is that although the "reply" link appears under each comment it doesn't work as expected. It simply creates an anchor link to the comment it is under, and scrolls it to the top of the viewport. Example:

<a rel="nofollow" class="comment-reply-link" href="#comment-3" data-commentid="3" data-postid="2679" data-belowelement="comment-3" data-respondelement="respond" data-replyto="Reply to [name]" aria-label="Reply to [name]">Reply</a>

The hover label in the browser for this shows: Go to #comment-3 on this page.

Why is this happening? How can I make it behave as expected?

本文标签: Why does the reply link in comments template scroll to comment position