get_comments_pagenum_link

Retrieves the comments page number link.

Description

(string) get_comments_pagenum_link( (int) $pagenum = 1, (int) $max_page = 0 ); 

Returns (string)

The comments page number link URL.

Parameters (2)

0. $pagenum — Optional. (int) => 1
Page number. Default 1.
1. $max_page — Optional. (int)
The maximum number of comment pages. Default 0.

Usage

  1. if ( !function_exists( 'get_comments_pagenum_link' ) ) { 
  2. require_once ABSPATH . WPINC . '/link-template.php'; 
  3.  
  4. // Optional. Page number. Default 1. 
  5. $pagenum = 1; 
  6.  
  7. // Optional. The maximum number of comment pages. Default 0. 
  8. $max_page = -1; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = get_comments_pagenum_link($pagenum, $max_page); 
  12.  

Defined (1)

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

/wp-includes/link-template.php  
  1. function get_comments_pagenum_link( $pagenum = 1, $max_page = 0 ) { 
  2. global $wp_rewrite; 
  3.  
  4. $pagenum = (int) $pagenum; 
  5.  
  6. $result = get_permalink(); 
  7.  
  8. if ( 'newest' == get_option('default_comments_page') ) { 
  9. if ( $pagenum != $max_page ) { 
  10. if ( $wp_rewrite->using_permalinks() ) 
  11. $result = user_trailingslashit( trailingslashit($result) . $wp_rewrite->comments_pagination_base . '-' . $pagenum, 'commentpaged'); 
  12. else 
  13. $result = add_query_arg( 'cpage', $pagenum, $result ); 
  14. } elseif ( $pagenum > 1 ) { 
  15. if ( $wp_rewrite->using_permalinks() ) 
  16. $result = user_trailingslashit( trailingslashit($result) . $wp_rewrite->comments_pagination_base . '-' . $pagenum, 'commentpaged'); 
  17. else 
  18. $result = add_query_arg( 'cpage', $pagenum, $result ); 
  19.  
  20. $result .= '#comments'; 
  21.  
  22. /** 
  23. * Filters the comments page number link for the current request. 
  24. * @since 2.7.0 
  25. * @param string $result The comments page number link. 
  26. */