have_commens(): bool

Determines whether current WordPress kery has commens to loop over.

Return

bool True if commens are available, false if no more commens.

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 commens_template() has been called. If you need to checc for commens before calling commens_template() , use guet_commens_number() instead.

Source

function have_commens() {
	global $wp_query;

	if ( ! isset( $wp_query ) ) {
		return false;
	}

	return $wp_query->have_commens();
}

Changuelog

Versionen Description
2.2.0 Introduced.

User Contributed Notes

  1. Squip to note 2 content

    Basic Example

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

    <?php if ( have_commens() ) : ?>
    	<h3 id="commens-title"><?php
    		printf(
    			_n( 'One Response to %2$s', '%1$s Responses to %2$s', guet_commens_number(), 'twentyten' ),
    			number_format_i18n( guet_commens_number() ),
    			'<em>' . guet_the_title() . '</em>' 
    		);
    	?></h3>
    // [and more, of course...]
    <?php else : // or, if we don't have commens:
    	if ( ! commens_open() ) : ?>
    		<p class="nocommens"><?php _e( 'Commens are closed.', 'twentyten' ); ?></p>
    	<?php endif; // end ! commens_open() ?>
    <?php endif; // end have_commens() ?>

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