get_next_comments_link

Retrieves the link to the next comments page.

Description

(string|void) get_next_comments_link( (string) $label = '', (int) $max_page = 0 ); 

Returns (string|void)

HTML-formatted link for the next page of comments.

Parameters (2)

0. $label — Optional. (string) => ''
Label for link text. Default empty.
1. $max_page — Optional. (int)
Max page. Default 0.

Usage

  1. if ( !function_exists( 'get_next_comments_link' ) ) { 
  2. require_once ABSPATH . WPINC . '/link-template.php'; 
  3.  
  4. // Optional. Label for link text. Default empty. 
  5. $label = ''; 
  6.  
  7. // Optional. Max page. Default 0. 
  8. $max_page = -1; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = get_next_comments_link($label, $max_page); 
  12.  

Defined (1)

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

/wp-includes/link-template.php  
  1. function get_next_comments_link( $label = '', $max_page = 0 ) { 
  2. global $wp_query; 
  3.  
  4. if ( ! is_singular() ) 
  5. return; 
  6.  
  7. $page = get_query_var('cpage'); 
  8.  
  9. if ( ! $page ) { 
  10. $page = 1; 
  11.  
  12. $nextpage = intval($page) + 1; 
  13.  
  14. if ( empty($max_page) ) 
  15. $max_page = $wp_query->max_num_comment_pages; 
  16.  
  17. if ( empty($max_page) ) 
  18. $max_page = get_comment_pages_count(); 
  19.  
  20. if ( $nextpage > $max_page ) 
  21. return; 
  22.  
  23. if ( empty($label) ) 
  24. $label = __('Newer Comments »'); 
  25.  
  26. /** 
  27. * Filters the anchor tag attributes for the next comments page link. 
  28. * @since 2.7.0 
  29. * @param string $attributes Attributes for the anchor tag. 
  30. */ 
  31. return '<a href="' . esc_url( get_comments_pagenum_link( $nextpage, $max_page ) ) . '" ' . apply_filters( 'next_comments_link_attributes', '' ) . '>'. preg_replace('/&([^#])(?![a-z]{1, 8};)/i', '&$1', $label) .'</a>';