我在 wordpress 中设置了一个 comment() 条件。就像 wordpress 默认主题一样,这个条件在 comments.php 中设置。
然后使用comment_template加载整个comments.php文件;现在,当我删除 have_comments() 条件时,一切正常并且所有评论都已加载,但是当我添加此条件时,它返回 false,就好像没有评论一样。
这是我的整个 comments.php 文件:
<?php
/**
| This page deals with the comment-system and template in the Behdis Marketing Group Wordpress Theme.
**/
$commenter = wp_get_current_commenter();
$req = get_option( 'require_name_email' );
$aria_req = ( $req ? " aria-required='true'" : '' );
$fields = array(
'author' => "<div><input type='text' name='author' placeholder='Full Name' /></div>",
'email' => "<div><input type='text' name='email' placeholder='Email /></div>",
);
$comments_args = array(
'fields' => $fields,
'comment_field' => "<div class=\"comment-component\"><textarea name=\"comment\" id=\"comment\" ></textarea></div>",
'comment_notes_after' => '',
'title_reply' => 'Write your comment...',
'title_reply_to' => 'Reply',
'label_submit' => 'Comment!',
'comment_notes_before' => "<p class='simple-title'>" . 'Your email is kept secret forever' . ' '
);
comment_form($comments_args);
?>
<?php
if( have_comments() )
{
?>
<section class='post-comments'>
<?php
$comments = get_comments();
foreach($comments as $comm)
{
?>
<div class='post-each-comment'>
<p class="post-each-comment-meta">
<?php echo $comm->comment_author;?> در تاریخ <?php comment_time();?>
</p>
<?php echo $comm->comment_content; ?>
</div>
<?php
}
?>
</section>
<?php
}// end of have_comments()
else
{
?>
<div class='no-comment' >
No comments, be the first visitor to comment on this post!
</div>
<?php
}
?>
提前致谢