WordPress at a glance

wp_link_pages() WP 1.0

The formatted output of a list of pages.

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

  • Global. Int. $page
  • Global. Int. $numpages
  • Global. Int. $multipage
  • Global. Int. $more
Hooks from function:
Return

String. Formatted output in HTML.

Usage

wp_link_pages( $args );
$args(string/array)

Array or string of default arguments.

  • $before (string)
    HTML or text to prepend to each link.
    Default: <p> Pages:

  • $after (string)
    HTML or text to append to each link.
    Default: </p>

  • $link_before (string)
    HTML or text to prepend to each link, inside the <a> tag. Also prepended to the current item, which is not linked.
    Default: ''

  • $link_after (string)
    HTML or text to append to each Pages link inside the <a> tag. Also appended to the current item, which is not linked.
    Default: ''

  • $next_or_number (string)
    Indicates whether page numbers should be used. Valid values are number and next.
    Default: 'number'

  • $separator (string)
    Text between pagination links.
    Default: ' '

  • $nextpagelink (string)
    Link text for the next page link, if available.
    Default: 'Next Page'

  • $previouspagelink (string)
    Link text for the previous page link, if available.
    Default: 'Previous Page'

  • $pagelink (string)
    Format string for page numbers. The % in the parameter string will be replaced with the page number, so 'Page %' generates "Page 1", "Page 2", etc.
    Default: '%', just the page number

  • $echo (int/true/false)
    Whether to echo or not. Accepts 1|true or 0|false.
    Default: 1|true

Default: ''

Code of wp_link_pages: wp-includes/post-template.php VER 4.9.8

<?php
function wp_link_pages( $args = '' ) {
	global $page, $numpages, $multipage, $more;

	$defaults = array(
		'before'           => '<p>' . __( 'Pages:' ),
		'after'            => '</p>',
		'link_before'      => '',
		'link_after'       => '',
		'next_or_number'   => 'number',
		'separator'        => ' ',
		'nextpagelink'     => __( 'Next page' ),
		'previouspagelink' => __( 'Previous page' ),
		'pagelink'         => '%',
		'echo'             => 1
	);

	$params = wp_parse_args( $args, $defaults );

	/**
	 * Filters the arguments used in retrieving page links for paginated posts.
	 *
	 * @since 3.0.0
	 *
	 * @param array $params An array of arguments for page links for paginated posts.
	 */
	$r = apply_filters( 'wp_link_pages_args', $params );

	$output = '';
	if ( $multipage ) {
		if ( 'number' == $r['next_or_number'] ) {
			$output .= $r['before'];
			for ( $i = 1; $i <= $numpages; $i++ ) {
				$link = $r['link_before'] . str_replace( '%', $i, $r['pagelink'] ) . $r['link_after'];
				if ( $i != $page || ! $more && 1 == $page ) {
					$link = _wp_link_page( $i ) . $link . '</a>';
				}
				/**
				 * Filters the HTML output of individual page number links.
				 *
				 * @since 3.6.0
				 *
				 * @param string $link The page number HTML output.
				 * @param int    $i    Page number for paginated posts' page links.
				 */
				$link = apply_filters( 'wp_link_pages_link', $link, $i );

				// Use the custom links separator beginning with the second link.
				$output .= ( 1 === $i ) ? ' ' : $r['separator'];
				$output .= $link;
			}
			$output .= $r['after'];
		} elseif ( $more ) {
			$output .= $r['before'];
			$prev = $page - 1;
			if ( $prev > 0 ) {
				$link = _wp_link_page( $prev ) . $r['link_before'] . $r['previouspagelink'] . $r['link_after'] . '</a>';

				/** This filter is documented in wp-includes/post-template.php */
				$output .= apply_filters( 'wp_link_pages_link', $link, $prev );
			}
			$next = $page + 1;
			if ( $next <= $numpages ) {
				if ( $prev ) {
					$output .= $r['separator'];
				}
				$link = _wp_link_page( $next ) . $r['link_before'] . $r['nextpagelink'] . $r['link_after'] . '</a>';

				/** This filter is documented in wp-includes/post-template.php */
				$output .= apply_filters( 'wp_link_pages_link', $link, $next );
			}
			$output .= $r['after'];
		}
	}

	/**
	 * Filters the HTML output of page links for paginated posts.
	 *
	 * @since 3.6.0
	 *
	 * @param string $output HTML output of paginated posts' page links.
	 * @param array  $args   An array of arguments.
	 */
	$html = apply_filters( 'wp_link_pages', $output, $args );

	if ( $r['echo'] ) {
		echo $html;
	}
	return $html;
}

Related Functions

From category: Pages

More from Template Tags: Posts, Pages, ...

No comments
    Hello, !     Log In . Register