Enrique Moreno Tent
Enrique Moreno Tent

Reputation: 25317

Wordpress comments not showing

Immaking my first theme and Im trying to show comments on the post, but for some reason its not working.

This is single.php:

comments_template();        //SOmeone said its necessary...

echo get_comments_number(); //This returns 2

if (have_comments()):       //This returns "Has not"
    echo "Has";
else:
    echo "Has not";
endif;

What am I missing?

Upvotes: 1

Views: 2061

Answers (3)

syseng
syseng

Reputation: 1

Solution from 2012 by @ariefbayu works yet. You may create template for comments as comments.php and add your code of comments

if (have_comments()):
echo "Has";
else:
    echo "Has not";
endif;

Then in template part single.php call the function comments_template(); in comment block, ex.:

<article>
// Your full news
    <div class="comments">
        <?php comments_template(); ?>
    </div>
</article>

Upvotes: 0

random_user_name
random_user_name

Reputation: 26180

You have to call comments_template() first, otherwise have_comments() does not work.

Don't ask me why, it's an idiosyncrasy of WordPress.

Upvotes: 3

buley
buley

Reputation: 29318

Try getting the comments array and iterating through it.

$comment_array = array_reverse(get_approved_comments($wp_query->post->ID));
    foreach( $comment_array as $comment) {
        var_dump( $comment );
    }

FYI, there's also this great StackExchange site

Upvotes: 0

Related Questions