1

I have set a comment() condition in wordpress. This condition is set in comments.php just as the wordpress default theme does. then the whole comments.php file is loaded using comment_template; Now, when I remove have_comments() condition, everything works and all the comments are loaded, but when I add this condition, it returns false as if there are no comments. Here is my whole comments.php file:

<?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   
    }
    ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.