WordPress的have_comments不起作用

要求莫斯塔法

我已经在wordpress中设置了comment()条件。就像wordpress默认主题一样,在comment.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   
    }
    ?>

提前致谢

哈克雷

在致电have_comments()之前先致电get_comments()

这很可能是您在此处处理流程错误的问题。Wordpress利用了全局静态,因此事物的顺序很重要(而且很容易遗漏):

<?php

    $comments = get_comments();

    if( have_comments() )
    {       
?>
<section class='post-comments'>

    <?php        
        foreach($comments as $comm)
        {
            ?>
            <div class='post-each-comment'>

另外,Codex说,这have_comments()取决于循环$post甚至可能是我上面的示例代码建议也无法使其正确处理静态状态,因此您需要进行一些故障排除以找出要使用的内容。

例如,作为get_comments()返回数组,通常这样做:

<?php

    $comments = get_comments();

    if( $comments )
    {       
?>
<section class='post-comments'>

    <?php        
        foreach($comments as $comm)
        {
            ?>
            <div class='post-each-comment'>

如您所见,have_comments()不必致电

希望这会有所帮助并保重。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

WordPress入队不起作用

来自分类Dev

ShortCode Wordpress不起作用

来自分类Dev

WordPress 包含不起作用

来自分类Dev

WordPress have_posts()在Functions.php中不起作用

来自分类Dev

Ajax在Wordpress管理中不起作用

来自分类Dev

Wordpress删除操作不起作用

来自分类Dev

Sidr导航在Wordpress中不起作用

来自分类Dev

trim()函数在wordpress中不起作用

来自分类Dev

wordpress ajax表单提交不起作用?

来自分类Dev

jQuery和Wordpress链接不起作用

来自分类Dev

jQuery在WordPress上不起作用

来自分类Dev

Wordpress-Header()不起作用

来自分类Dev

htaccess regex wordpress不起作用

来自分类Dev

lang选项在wordpress中不起作用

来自分类Dev

Wordpress AJAX不起作用-响应0

来自分类Dev

如果语句在WordPress中不起作用

来自分类Dev

WordPress主题+ SSL不起作用

来自分类Dev

WordPress的WPDB更新不起作用

来自分类Dev

wordpress-category__not_in不起作用

来自分类Dev

WordPress:<a>中的页面链接不起作用

来自分类Dev

粘性插件在WordPress上不起作用?

来自分类Dev

.click()在WordPress插件中不起作用

来自分类Dev

jQuery灯箱插件不起作用(Wordpress)

来自分类Dev

Wordpress菜单CSS类不起作用

来自分类Dev

JQuery在Wordpress中似乎不起作用

来自分类Dev

Wordpress Javascript变量不起作用

来自分类Dev

WordPress + Ajax更新记录不起作用

来自分类Dev

htaccess regex wordpress不起作用

来自分类Dev

Wordpress分类模板不起作用