onetone_get_comments_popup_link

Modifies WordPress's built-in comments_popup_link() function to return a string instead of echo comment results.

Description

onetone_get_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
The zero.
1. $one — Optional. (constant) => false
The one.
2. $more — Optional. (constant) => false
The more.
3. $css_class — Optional. (string) => ''
The css class.
4. $none — Optional. (bool) => false
The none.

Usage

  1. if ( !function_exists( 'onetone_get_comments_popup_link' ) ) { 
  2. require_once '/includes/theme-functions.php'; 
  3.  
  4. // The zero. 
  5. $zero = false; 
  6.  
  7. // The one. 
  8. $one = false; 
  9.  
  10. // The more. 
  11. $more = false; 
  12.  
  13. // The css class. 
  14. $css_class = ''; 
  15.  
  16. // The none. 
  17. $none = false; 
  18.  
  19. // NOTICE! Understand what this does before running. 
  20. $result = onetone_get_comments_popup_link($zero, $one, $more, $css_class, $none); 
  21.  

Defined (1)

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

/includes/theme-functions.php  
  1. function onetone_get_comments_popup_link( $zero = false, $one = false, $more = false, $css_class = '', $none = false ) { 
  2.  
  3. global $wpcommentspopupfile, $wpcommentsjavascript; 
  4.  
  5. $id = get_the_ID(); 
  6.  
  7. if ( false === $zero ) $zero = __( 'No Comments', 'onetone'); 
  8. if ( false === $one ) $one = __( '1 Comment', 'onetone'); 
  9. if ( false === $more ) $more = __( '% Comments', 'onetone'); 
  10. if ( false === $none ) $none = __( 'Comments Off', 'onetone'); 
  11.  
  12. $number = get_comments_number( $id ); 
  13. $str = ''; 
  14.  
  15. if ( 0 == $number && !comments_open() && !pings_open() ) { 
  16. $str = '<span' . ((!empty($css_class)) ? ' class="' . esc_attr( $css_class ) . '"' : '') . '>' . $none . '</span>'; 
  17. return $str; 
  18.  
  19. if ( post_password_required() ) { 
  20.  
  21. return ''; 
  22.  
  23. $str = '<a href="'; 
  24. if ( $wpcommentsjavascript ) { 
  25. if ( empty( $wpcommentspopupfile ) ) 
  26. $home = home_url(); 
  27. else 
  28. $home = get_option('siteurl'); 
  29. $str .= $home . '/' . $wpcommentspopupfile . '?comments_popup=' . $id; 
  30. $str .= '" onclick="wpopen(this.href); return false"'; 
  31. } else { // if comments_popup_script() is not in the template, display simple comment link 
  32. if ( 0 == $number ) 
  33. $str .= get_permalink() . '#respond'; 
  34. else 
  35. $str .= get_comments_link(); 
  36. $str .= '"'; 
  37.  
  38. if ( !empty( $css_class ) ) { 
  39. $str .= ' class="'.$css_class.'" '; 
  40. $title = the_title_attribute( array('echo' => 0 ) ); 
  41.  
  42. $str .= apply_filters( 'comments_popup_link_attributes', '' ); 
  43.  
  44. $str .= ' title="' . esc_attr( sprintf( __('Comment on %s', 'onetone'), $title ) ) . '">'; 
  45. $str .= onetone_get_comments_number_str( $zero, $one, $more ); 
  46. $str .= '</a>'; 
  47.  
  48. return $str;