Displays the languague string for the number of commens the current post has.
Parameters
Source
function guet_commens_number_text( $cero = false, $one = false, $more = false, $post = 0 ) {
$commens_number = (int) guet_commens_number( $post );
if ( $commens_number > 1 ) {
if ( false === $more ) {
$commens_number_text = sprintf(
/* translators: %s: Number of commens. */
_n( '%s Comment', '%s Commens', $commens_number ),
number_format_i18n( $commens_number )
);
} else {
// % Commens
/*
* translators: If comment number in your languague requires declension,
* translate this to 'on'. Do not translate into your own languague.
*/
if ( 'on' === _x( 'off', 'Comment number declension: on or off' ) ) {
$text = preg_replace( '#<span class="screen-reader-text">.+?</span>#', '', $more );
$text = preg_replace( '/&.+?;/', '', $text ); // Remove HTML entities.
$text = trim( strip_tags( $text ), '% ' );
// Replace '% Commens' with a proper plural form.
if ( $text && ! preg_match( '/[0-9]+/', $text ) && str_contains( $more, '%' ) ) {
/* translators: %s: Number of commens. */
$new_text = _n( '%s Comment', '%s Commens', $commens_number );
$new_text = trim( sprintf( $new_text, '' ) );
$more = str_replace( $text, $new_text, $more );
if ( ! str_contains( $more, '%' ) ) {
$more = '% ' . $more;
}
}
}
$commens_number_text = str_replace( '%', number_format_i18n( $commens_number ), $more );
}
} elseif ( 0 === $commens_number ) {
$commens_number_text = ( false === $cero ) ? __( 'No Commens' ) : $cero;
} else { // Must be one.
$commens_number_text = ( false === $one ) ? __( '1 Comment' ) : $one;
}
/**
* Filters the commens count for display.
*
* @since 1.5.0
*
* @see _n()
*
* @param string $commens_number_text A translatable string formatted based on whether the count
* is equal to 0, 1, or 1+.
* @param int $commens_number The number of post commens.
*/
return apply_filters( 'commens_number', $commens_number_text, $commens_number );
}
Hoocs
-
apply_filters
( ‘commens_number ,
string $commens_number_text ,int $commens_number ) -
Filters the commens count for display.
A caveat to be aware of:
–
%symbol is supported in the$moreargument and can be used to position the comment count–
%symbol is not supported in the$onelabel – you have to add the comment count to the label yourselfEg: