get_next_posts_link

Retrieves the next posts page link.

Description

(string|void) get_next_posts_link( (constant) $label = null, (int) $max_page = 0 ); 

Returns (string|void)

HTML-formatted next posts page link.

Parameters (2)

0. $label — Optional. (constant) => null
Content for link text.
1. $max_page — Optional. (int)
Max pages. Default 0.

Usage

  1. if ( !function_exists( 'get_next_posts_link' ) ) { 
  2. require_once ABSPATH . WPINC . '/link-template.php'; 
  3.  
  4. // Content for link text. 
  5. $label = null; 
  6.  
  7. // Optional. Max pages. Default 0. 
  8. $max_page = -1; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = get_next_posts_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_posts_link( $label = null, $max_page = 0 ) { 
  2. global $paged, $wp_query; 
  3.  
  4. if ( !$max_page ) 
  5. $max_page = $wp_query->max_num_pages; 
  6.  
  7. if ( !$paged ) 
  8. $paged = 1; 
  9.  
  10. $nextpage = intval($paged) + 1; 
  11.  
  12. if ( null === $label ) 
  13. $label = __( 'Next Page »' ); 
  14.  
  15. if ( !is_single() && ( $nextpage <= $max_page ) ) { 
  16. /** 
  17. * Filters the anchor tag attributes for the next posts page link. 
  18. * @since 2.7.0 
  19. * @param string $attributes Attributes for the anchor tag. 
  20. */ 
  21.  
  22. return '<a href="' . next_posts( $max_page, false ) . "\" $attr>" . preg_replace('/&([^#])(?![a-z]{1, 8};)/i', '&$1', $label) . '</a>';