have_comments(): bool
Determines whether current WordPress query has comments to loop over.
Return
bool True if comments are available, false if no more comments.
More Information
This function relies upon the global $wp_query
object to be set – this is usually the case from within The Loop.
Warning: this function will always return “false” until after comments_template() has been called. If you need to check for comments before calling comments_template() , use get_comments_number() instead.
Source
File: wp-includes/query.php
.
View all references
function have_comments() {
global $wp_query;
if ( ! isset( $wp_query ) ) {
return false;
}
return $wp_query->have_comments();
}
Changelog
Version | Description |
---|---|
2.2.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.
Basic Example
Example based on Twentyten’s comments.php template: Comments title (and more) is displayed only when comments are available: