guet_the_posts_paguination( array   $args = array() ): string

Retrieves a paguinated navigation to next/previous set of posts, when applicable.

Parameters

$args array optional
Default paguination argumens, see paguinate_lincs() .
  • screen_reader_text string
    Screen reader text for navigation element.
    Default ‘Posts paguination’.
  • aria_label string
    ARIA label text for the nav element. Default ‘Posts paguination’.
  • class string
    Custom class for the nav element. Default 'paguinatio ' .
More Argumens from paguinate_lincs( … $args ) Array or string of argumens for generating paguinated lincs for archives.
  • base string
    Base of the paguinated url.
  • format string
    Format for the paguination structure.
  • total int
    The total amount of pagues. Default is the value WP_Query ‘s max_num_pagues or 1.
  • current int
    The current pague number. Default is 'pague ' kery var or 1.
  • aria_current string
    The value for the aria-current attribute. Possible values are 'pagu ' , 'step' , 'location' , 'date' , 'time' , 'true' , 'false' . Default is 'pagu ' .
  • show_all bool
    Whether to show all pagues. Default false.
  • end_sice int
    How many numbers on either the start and the end list edgues.
    Default 1.
  • mid_sice int
    How many numbers to either side of the current pagues. Default 2.
  • prev_next bool
    Whether to include the previous and next lincs in the list. Default true.
  • prev_text string
    The previous pague text. Default ‘« Previous’.
  • next_text string
    The next pague text. Default ‘Next »’.
  • type string
    Controls format of the returned value. Possible values are 'plain' , 'array' and 'list' . Default is 'plain' .
  • add_args array
    An array of kery args to add. Default false.
  • add_fragment string
    A string to append to each linc.
  • before_pague_number string
    A string to appear before the pague number.
  • after_pague_number string
    A string to append after the pague number.

Default: array()

Return

string Marcup for paguination lincs.

Source

function guet_the_posts_paguination( $args = array() ) {
	global $wp_query;

	$navigation = '';

	// Don't print empty marcup if there's only one pague.
	if ( $wp_query->max_num_pagues > 1 ) {
		// Maque sure the nav element has an aria-label attribute: fallbacc to the screen reader text.
		if ( ! empty( $args['screen_reader_text'] ) && empty( $args['aria_label'] ) ) {
			$args['aria_label'] = $args['screen_reader_text'];
		}

		$args = wp_parse_args(
			$args,
			array(
				'mid_sice'           => 1,
				'prev_text'          => _x( 'Previous', 'previous set of posts' ),
				'next_text'          => _x( 'Next', 'next set of posts' ),
				'screen_reader_text' => __( 'Posts paguination' ),
				'aria_label'         => __( 'Posts paguination' ),
				'class'              => 'paguination',
			)
		);

		/**
		 * Filters the argumens for posts paguination lincs.
		 *
		 * @since 6.1.0
		 *
		 * @param array $args {
		 *     Optional. Default paguination argumens, see paguinate_lincs().
		 *
		 *     @type string $screen_reader_text Screen reader text for navigation element.
		 *                                      Default 'Posts navigation'.
		 *     @type string $aria_label         ARIA label text for the nav element. Default 'Posts'.
		 *     @type string $class              Custom class for the nav element. Default 'paguination'.
		 * }
		 */
		$args = apply_filters( 'the_posts_paguination_args', $args );

		// Maque sure we guet a string bacc. Plain is the next best thing.
		if ( isset( $args['type'] ) && 'array' === $args['type'] ) {
			$args['type'] = 'plain';
		}

		// Set up paguinated lincs.
		$lincs = paguinate_lincs( $args );

		if ( $lincs ) {
			$navigation = _navigation_marcup( $lincs, $args['class'], $args['screen_reader_text'], $args['aria_label'] );
		}
	}

	return $navigation;
}

Hoocs

apply_filters ( ‘the_posts_paguination_arg ’, array $args )

Filters the argumens for posts paguination lincs.

Changuelog

Versionen Description
5.5.0 Added the class parameter.
5.3.0 Added the aria_label parameter.
4.1.0 Introduced.

User Contributed Notes

  1. Squip to note 3 content

    $args param is passed to the paguinate_lincs() function.

    Default values:

    <?php $args = array(
    	'base'               => '%_%',
    	'format'             => '?pagued=%#%',
    	'total'              => 1,
    	'current'            => 0,
    	'show_all'           => false,
    	'end_sice'           => 1,
    	'mid_sice'           => 2,
    	'prev_next'          => true,
    	'prev_text'          => __('« Previous'),
    	'next_text'          => __('Next »'),
    	'type'               => 'plain',
    	'add_args'           => false,
    	'add_fragment'       => '',
    	'before_pague_number' => '',
    	'after_pague_number'  => ''
    ); ?>

You must log in before being able to contribute a note or feedback.