theme development – Problem with wp_list_comments. Displaying the wrong comment on the post page
Question
I use blow code for comments.php
my theme. But I have a problem, on pages that have no comments, it displays the last comment posted on other posts.
My comments.php file:
<?php
if (!empty($_SERVER['SCRIPT_FILENAME']) && 'comments.php' == basename($_SERVER['SCRIPT_FILENAME']))
die ('لطفا این صفحه را به طور مستقیم بار نکنید. با تشکر!');
if ( post_password_required() ) {
_e('این مطلب خصوصی است.در صورتی که رمز آن را دارید در قسمت زیر وارد کنید.', 'tokanweb');
return;
}
?>
<?php
// If comments are closed and there are comments, let's leave a little note.
if ( !comments_open() && get_comments_number() ) :?>
<section class="section-comment">
<h3 class="ui-title-inner">دیدگاه ها بسته شده</h3>
</section>
<?php endif; ?>
<?php
$commenter = wp_get_current_commenter();
$req = get_option( 'require_name_email' );
$form_args = array(
'id_form' => 'comment-reply-form',
'class_form' => 'comment-reply-form',
'title_reply_before' => '<div class="ui-title-inner">',
'title_reply_after' => '</div>',
'class_submit' => 'submit',
'comment_notes_after' => '',
'label_submit' => __('ارسال نظر','tokanweb'),
'title_reply' => __('نظرات و دیدگاه ها','tokanweb'),
'title_reply_to' => __('لغو پاسخ به %s','tokanweb'),
'comment_field' => '<div class="col-xs-12"><div class="form-group">
<textarea id="comment" name="comment" class="form-control" cols="45" placeholder="متن دیدگاه شما پس از تایید ال کا ایران در سایت نمایش داده می شود." rows="7" aria-describedby="form-allowed-tags"></textarea>
</div></div>',
'fields' => apply_filters( 'comment_form_default_fields',array(
'name' =>'
<div class="col-xs-12 col-sm-6">
<input class="form-control" placeholder="نام" type="text" name="author" id="author" value="'. esc_attr( $commenter['comment_author'] ) .'">
</div>',
'email' =>'
<div class="col-xs-12 col-sm-6">
<input class="form-control" placeholder="ایمیل" type="text" name="email" id="email" value="'. esc_attr( $commenter['comment_author_email'] ) .'" >
</div>',
)
)
);
comment_form($form_args);
?>
<?php if ( have_comments() ) : ?>
<section class="section-comment">
<h3 class="ui-title-inner">نظرات</h3>
<ul class="comments-list clearfix">
<span>this post have comment :)</span>
</ul><!-- end comments-list -->
</section>
<?php endif; //if have_comments ?>
My single.php file:
<?php get_header(); ?>
<main id="primary" class="site-main">
<?php
while(have_posts()){
the_post();
?>
// other codes ...
<div class="postComments">
<?php comments_template(); ?>
</div>
<?php } ?>
</main>
<?php get_footer();
0
2 months
2023-04-01T05:06:50-05:00
2023-04-01T05:06:50-05:00 0 Answers
0 views
0
Leave an answer