get_comments_number_text

Display the language string for the number of comments the current post has.

Description

get_comments_number_text( (constant) $zero = false, (constant) $one = false, (bool) $more = false ); 

Parameters (3)

0. $zero — Optional. (constant) => false
Text for no comments. Default false.
1. $one — Optional. (constant) => false
Text for one comment. Default false.
2. $more — Optional. (bool) => false
Text for more than one comment. Default false.

Usage

  1. if ( !function_exists( 'get_comments_number_text' ) ) { 
  2. require_once ABSPATH . WPINC . '/comment-template.php'; 
  3.  
  4. // Optional. Text for no comments. Default false. 
  5. $zero = false; 
  6.  
  7. // Optional. Text for one comment. Default false. 
  8. $one = false; 
  9.  
  10. // Optional. Text for more than one comment. Default false. 
  11. $more = false; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = get_comments_number_text($zero, $one, $more); 
  15.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/comment-template.php  
  1. function get_comments_number_text( $zero = false, $one = false, $more = false ) { 
  2. $number = get_comments_number(); 
  3.  
  4. if ( $number > 1 ) { 
  5. if ( false === $more ) { 
  6. /** translators: %s: number of comments */ 
  7. $output = sprintf( _n( '%s Comment', '%s Comments', $number ), number_format_i18n( $number ) ); 
  8. } else { 
  9. // % Comments 
  10. /** translators: If comment number in your language requires declension,  
  11. * translate this to 'on'. Do not translate into your own language. 
  12. */ 
  13. if ( 'on' === _x( 'off', 'Comment number declension: on or off' ) ) { 
  14. $text = preg_replace( '#<span class="screen-reader-text">.+?</span>#', '', $more ); 
  15. $text = preg_replace( '/&.+?;/', '', $text ); // Kill entities 
  16. $text = trim( strip_tags( $text ), '% ' ); 
  17.  
  18. // Replace '% Comments' with a proper plural form 
  19. if ( $text && ! preg_match( '/[0-9]+/', $text ) && false !== strpos( $more, '%' ) ) { 
  20. /** translators: %s: number of comments */ 
  21. $new_text = _n( '%s Comment', '%s Comments', $number ); 
  22. $new_text = trim( sprintf( $new_text, '' ) ); 
  23.  
  24. $more = str_replace( $text, $new_text, $more ); 
  25. if ( false === strpos( $more, '%' ) ) { 
  26. $more = '% ' . $more; 
  27.  
  28. $output = str_replace( '%', number_format_i18n( $number ), $more ); 
  29. } elseif ( $number == 0 ) { 
  30. $output = ( false === $zero ) ? __( 'No Comments' ) : $zero; 
  31. } else { // must be one 
  32. $output = ( false === $one ) ? __( '1 Comment' ) : $one; 
  33. /** 
  34. * Filters the comments count for display. 
  35. * @since 1.5.0 
  36. * @see _n() 
  37. * @param string $output A translatable string formatted based on whether the count 
  38. * is equal to 0, 1, or 1+. 
  39. * @param int $number The number of post comments. 
  40. */ 
  41. return apply_filters( 'comments_number', $output, $number );