rozwój motywu – Problem z wp_list_comments. Wyświetlanie niewłaściwego komentarza na stronie posta
![rozwój motywu – Problem z wp_list_comments. Wyświetlanie niewłaściwego komentarza na stronie posta](https://oen.pl/wp-content/uploads/2023/01/apple-touch-icon@2.png)
Używam kodu ciosu dla comments.php
mój motyw. Ale mam problem, na stronach, które nie mają komentarzy, wyświetla ostatni komentarz opublikowany w innych postach.
Mój plik komentarze.php:
<?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 ?>
Mój pojedynczy plik.php:
<?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();