Php 为什么我所有的评论都出现在所有的帖子上?WordPress

Php 为什么我所有的评论都出现在所有的帖子上?WordPress,php,wordpress,comments,Php,Wordpress,Comments,我正在努力学习WordPress开发,目前正在构建我自己的主题,所以我没有使用现有的主题。我对我的评论有一个我无法理解的问题 基本上,当我在我的一篇文章下面添加一条评论时,这条评论会显示在所有的文章上。我已经尝试删除代码的某些部分,但我仍然不明白为什么每个评论都会出现在每个帖子下面 以下是不同的代码片段: 在我的博客帖子模板上,我有以下评论部分: <h2 class="white centered"> <?php $totalcomment

我正在努力学习WordPress开发,目前正在构建我自己的主题,所以我没有使用现有的主题。我对我的评论有一个我无法理解的问题

基本上,当我在我的一篇文章下面添加一条评论时,这条评论会显示在所有的文章上。我已经尝试删除代码的某些部分,但我仍然不明白为什么每个评论都会出现在每个帖子下面

以下是不同的代码片段:

在我的博客帖子模板上,我有以下评论部分:

    <h2 class="white centered"> <?php

    $totalcomments = get_comments_number();

    if ($totalcomments == "0") {
  echo "There are no comments yet ...";

} elseif ($totalcomments == "1")  {
  echo "Join the discussion! <p> There is already " .  $totalcomments . " Comment";
}

else {
echo "Join the discussion! <p> There are already " .  $totalcomments . " Comments";
}

    ?> </h2>

<?php
    if (comments_open()){
        comments_template();
    }
?>

</div>

然后我创建了我的comments.php,代码如下:

if (have_comments()) : ?>
    <ol class="post-comments">
        <?php
            wp_list_comments(array(
                'style'       => 'ol',
                'short_ping'  => true,
                                'avatar_size' => 60,
            ));
        ?>
    </ol>
        <?php
endif;
?>




<?php comment_form(array
  ('title_reply' => 'Have any questions, thoughts or ideas you would like to share?',
  )
); ?>




<?php
if (is_singular() && comments_open() && (get_option('thread_comments') == 1)) {
    wp_enqueue_script('comment-reply', 'wp-includes/js/comment-reply', array(), false, true);
}
?>
function gb_comment_form_tweaks ($fields) {
    //add placeholders and remove labels
    $fields['author'] = '<input id="author" name="author" value="" placeholder="Name*" size="30" maxlength="245" required="required" type="text">';

    $fields['email'] = '<input id="email" name="email" type="email" value="" placeholder="Email*" size="30" maxlength="100" aria-describedby="email-notes" required="required">';

    $fields['comment'] = '<textarea id="comment" name="comment" cols="45" rows="8" maxlength="65525" placeholder="Comment*" required="required"></textarea>';

    //remove website
    unset($fields['url']);

    return $fields;
}

add_filter('comment_form_fields', 'gb_comment_form_tweaks');
if(have_comments()):?>
在我的function.php中,我添加了以下代码:

if (have_comments()) : ?>
    <ol class="post-comments">
        <?php
            wp_list_comments(array(
                'style'       => 'ol',
                'short_ping'  => true,
                                'avatar_size' => 60,
            ));
        ?>
    </ol>
        <?php
endif;
?>




<?php comment_form(array
  ('title_reply' => 'Have any questions, thoughts or ideas you would like to share?',
  )
); ?>




<?php
if (is_singular() && comments_open() && (get_option('thread_comments') == 1)) {
    wp_enqueue_script('comment-reply', 'wp-includes/js/comment-reply', array(), false, true);
}
?>
function gb_comment_form_tweaks ($fields) {
    //add placeholders and remove labels
    $fields['author'] = '<input id="author" name="author" value="" placeholder="Name*" size="30" maxlength="245" required="required" type="text">';

    $fields['email'] = '<input id="email" name="email" type="email" value="" placeholder="Email*" size="30" maxlength="100" aria-describedby="email-notes" required="required">';

    $fields['comment'] = '<textarea id="comment" name="comment" cols="45" rows="8" maxlength="65525" placeholder="Comment*" required="required"></textarea>';

    //remove website
    unset($fields['url']);

    return $fields;
}

add_filter('comment_form_fields', 'gb_comment_form_tweaks');
函数gb\u注释\u表单\u调整($fields){
//添加占位符并删除标签
$fields['author']='';
$fields['email']='';
$fields['comment']='';
//删除网站
未设置($fields['url']);
返回$fields;
}
添加过滤器(“注释表单字段”、“gb注释表单调整”);
我没有创建一个额外的comment-template.php,它只是已经自动包含在WordPress中的一个


有人知道为什么我的每一条评论都出现在每篇帖子上吗?

有人能帮忙吗?我逐字删除了所有内容,只粘贴在应该显示评论的地方。但即使只有这一点点代码,每一条评论都会显示在每一篇文章上。我不知道为什么