Whether there are comments to loop over.

Description Description

Return Return


Top ↑

Source Source

File: wp-includes/query.php

function have_comments() {
	global $wp_query;
	return $wp_query->have_comments();

Top ↑

Changelog Changelog

Version Description
2.2.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 1 content
    Contributed by Codex

    Basic Example

    Example based on Twentyten’s comments.php template: Comments title (and more) is displayed only when comments are available:

    <?php if ( have_comments() ) : ?>
    	<h3 id="comments-title"><?php
    			_n( 'One Response to %2$s', '%1$s Responses to %2$s', get_comments_number(), 'twentyten' ),
    			number_format_i18n( get_comments_number() ),
    			'<em>' . get_the_title() . '</em>' 
    // [and more, of course...]
    <?php else : // or, if we don't have comments:
    	if ( ! comments_open() ) : ?>
    		<p class="nocomments"><?php _e( 'Comments are closed.', 'twentyten' ); ?></p>
    	<?php endif; // end ! comments_open() ?>
    <?php endif; // end have_comments() ?>

You must log in before being able to contribute a note or feedback.