comments_popup_link

Displays the link to the comments for the current post ID.

Description

comments_popup_link( (constant) $zero = false, (constant) $one = false, (constant) $more = false, (string) $css_class = '', (bool) $none = false ); 

Parameters (5)

0. $zero — Optional. (constant) => false
String to display when no comments. Default false.
1. $one — Optional. (constant) => false
String to display when only one comment is available. Default false.
2. $more — Optional. (constant) => false
String to display when there are more than one comment. Default false.
3. $css_class — Optional. (string) => ''
CSS class to use for comments. Default empty.
4. $none — Optional. (bool) => false
String to display when comments have been turned off. Default false.

Usage

  1. if ( !function_exists( 'comments_popup_link' ) ) { 
  2. require_once ABSPATH . WPINC . '/comment-template.php'; 
  3.  
  4. // Optional. String to display when no comments. Default false. 
  5. $zero = false; 
  6.  
  7. // Optional. String to display when only one comment is available. 
  8. // Default false. 
  9. $one = false; 
  10.  
  11. // Optional. String to display when there are more than one comment. 
  12. // Default false. 
  13. $more = false; 
  14.  
  15. // Optional. CSS class to use for comments. Default empty. 
  16. $css_class = ''; 
  17.  
  18. // Optional. String to display when comments have been turned off. 
  19. // Default false. 
  20. $none = false; 
  21.  
  22. // NOTICE! Understand what this does before running. 
  23. $result = comments_popup_link($zero, $one, $more, $css_class, $none); 
  24.  

Defined (1)

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

/wp-includes/comment-template.php  
  1. function comments_popup_link( $zero = false, $one = false, $more = false, $css_class = '', $none = false ) { 
  2. $id = get_the_ID(); 
  3. $title = get_the_title(); 
  4. $number = get_comments_number( $id ); 
  5.  
  6. if ( false === $zero ) { 
  7. /** translators: %s: post title */ 
  8. $zero = sprintf( __( 'No Comments<span class="screen-reader-text"> on %s</span>' ), $title ); 
  9.  
  10. if ( false === $one ) { 
  11. /** translators: %s: post title */ 
  12. $one = sprintf( __( '1 Comment<span class="screen-reader-text"> on %s</span>' ), $title ); 
  13.  
  14. if ( false === $more ) { 
  15. /** translators: 1: Number of comments 2: post title */ 
  16. $more = _n( '%1$s Comment<span class="screen-reader-text"> on %2$s</span>', '%1$s Comments<span class="screen-reader-text"> on %2$s</span>', $number ); 
  17. $more = sprintf( $more, number_format_i18n( $number ), $title ); 
  18.  
  19. if ( false === $none ) { 
  20. /** translators: %s: post title */ 
  21. $none = sprintf( __( 'Comments Off<span class="screen-reader-text"> on %s</span>' ), $title ); 
  22.  
  23. if ( 0 == $number && !comments_open() && !pings_open() ) { 
  24. echo '<span' . ((!empty($css_class)) ? ' class="' . esc_attr( $css_class ) . '"' : '') . '>' . $none . '</span>'; 
  25. return; 
  26.  
  27. _e( 'Enter your password to view comments.' ); 
  28. return; 
  29.  
  30. echo '<a href="'; 
  31. if ( 0 == $number ) { 
  32. $respond_link = get_permalink() . '#respond'; 
  33. /** 
  34. * Filters the respond link when a post has no comments. 
  35. * @since 4.4.0 
  36. * @param string $respond_link The default response link. 
  37. * @param integer $id The post ID. 
  38. */ 
  39. echo apply_filters( 'respond_link', $respond_link, $id ); 
  40. } else { 
  41. echo '"'; 
  42.  
  43. if ( !empty( $css_class ) ) { 
  44. echo ' class="'.$css_class.'" '; 
  45.  
  46. $attributes = ''; 
  47. /** 
  48. * Filters the comments link attributes for display. 
  49. * @since 2.5.0 
  50. * @param string $attributes The comments link attributes. Default empty. 
  51. */ 
  52.  
  53. echo '>'; 
  54. comments_number( $zero, $one, $more ); 
  55. echo '</a>';