Reputation: 25317
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
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
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
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