我已經在wordpress中設置了評論()條件。這個條件在comments.php中設置,就像WordPress的默認主題一樣。WordPress的have_comments不起作用
然後整個comments.php文件使用comment_template加載;現在,當我刪除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
}
?>
在此先感謝
抱歉,您的意思是我必須在get_comments()之後放置have_comments()?我已經在上面的代碼之前測試過了,它們都不起作用。 –
@Mostafa:正如所寫的,可能不會這樣做,請參閱第二個例子,它根本不使用'has_comments()'。 AFAIK'has_comments()'用於循環頁面而不是評論頁面。 – hakre
有人幫助我!我被這個問題阻止了 –