wp_link_pages

The formatted output of a list of pages.

Description

(string) wp_link_pages( (string) $args = '' ); 

Displays page links for paginated posts (i.e. includes the . Quicktag one or more times). This tag must be within The Loop.

Returns (string)

Formatted output in HTML.

Parameters (1)

0. $args — Optional. (string) => ''
Array or string of default arguments.

Options


Usage

  1. if ( !function_exists( 'wp_link_pages' ) ) { 
  2. require_once ABSPATH . WPINC . '/post-template.php'; 
  3.  
  4. // Optional. Array or string of default arguments. 
  5. $args = array( 
  6. 'before' => 'is Pages:', 
  7. 'after' => 'is ', 
  8. 'link_before' => '', 
  9. 'link_after' => '', 
  10. 'next_or_number' => 'number', 
  11. 'separator' => ' ', 
  12. 'nextpagelink' => 'Next Page', 
  13. 'previouspagelink' => 'Previous Page', 
  14. 'pagelink' => '%' 
  15. ); 
  16.  
  17. // NOTICE! Understand what this does before running. 
  18. $result = wp_link_pages($args); 
  19.  

Defined (1)

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

/wp-includes/post-template.php  
  1. function wp_link_pages( $args = '' ) { 
  2. global $page, $numpages, $multipage, $more; 
  3.  
  4. $defaults = array( 
  5. 'before' => '<p>' . __( 'Pages:' ),  
  6. 'after' => '</p>',  
  7. 'link_before' => '',  
  8. 'link_after' => '',  
  9. 'next_or_number' => 'number',  
  10. 'separator' => ' ',  
  11. 'nextpagelink' => __( 'Next page' ),  
  12. 'previouspagelink' => __( 'Previous page' ),  
  13. 'pagelink' => '%',  
  14. 'echo' => 1 
  15. ); 
  16.  
  17. $params = wp_parse_args( $args, $defaults ); 
  18.  
  19. /** 
  20. * Filters the arguments used in retrieving page links for paginated posts. 
  21. * @since 3.0.0 
  22. * @param array $params An array of arguments for page links for paginated posts. 
  23. */ 
  24. $r = apply_filters( 'wp_link_pages_args', $params ); 
  25.  
  26. $output = ''; 
  27. if ( $multipage ) { 
  28. if ( 'number' == $r['next_or_number'] ) { 
  29. $output .= $r['before']; 
  30. for ( $i = 1; $i <= $numpages; $i++ ) { 
  31. $link = $r['link_before'] . str_replace( '%', $i, $r['pagelink'] ) . $r['link_after']; 
  32. if ( $i != $page || ! $more && 1 == $page ) { 
  33. $link = _wp_link_page( $i ) . $link . '</a>'; 
  34. /** 
  35. * Filters the HTML output of individual page number links. 
  36. * @since 3.6.0 
  37. * @param string $link The page number HTML output. 
  38. * @param int $i Page number for paginated posts' page links. 
  39. */ 
  40. $link = apply_filters( 'wp_link_pages_link', $link, $i ); 
  41.  
  42. // Use the custom links separator beginning with the second link. 
  43. $output .= ( 1 === $i ) ? ' ' : $r['separator']; 
  44. $output .= $link; 
  45. $output .= $r['after']; 
  46. } elseif ( $more ) { 
  47. $output .= $r['before']; 
  48. $prev = $page - 1; 
  49. if ( $prev > 0 ) { 
  50. $link = _wp_link_page( $prev ) . $r['link_before'] . $r['previouspagelink'] . $r['link_after'] . '</a>'; 
  51.  
  52. /** This filter is documented in wp-includes/post-template.php */ 
  53. $output .= apply_filters( 'wp_link_pages_link', $link, $prev ); 
  54. $next = $page + 1; 
  55. if ( $next <= $numpages ) { 
  56. if ( $prev ) { 
  57. $output .= $r['separator']; 
  58. $link = _wp_link_page( $next ) . $r['link_before'] . $r['nextpagelink'] . $r['link_after'] . '</a>'; 
  59.  
  60. /** This filter is documented in wp-includes/post-template.php */ 
  61. $output .= apply_filters( 'wp_link_pages_link', $link, $next ); 
  62. $output .= $r['after']; 
  63.  
  64. /** 
  65. * Filters the HTML output of page links for paginated posts. 
  66. * @since 3.6.0 
  67. * @param string $output HTML output of paginated posts' page links. 
  68. * @param array $args An array of arguments. 
  69. */ 
  70. $html = apply_filters( 'wp_link_pages', $output, $args ); 
  71.  
  72. if ( $r['echo'] ) { 
  73. echo $html; 
  74. return $html;