WordPress at a glance

get_the_posts_navigation() WP 1.0

Returns the navigation to next/previous set of posts, when applicable.

Notes:

  • Global. WP_Query. $wp_query WordPress Query object.
Is the basis for: the_posts_navigation()

No Hooks.

Return

String. Markup for posts links.

Usage

get_the_posts_navigation( $args );
$args(array)

Default empty array.

  • $prev_text (string)
    Anchor text to display in the previous posts link.
    Default: 'Older posts'

  • $next_text (string)
    Anchor text to display in the next posts link.
    Default: 'Newer posts'

  • $screen_reader_text (string)
    Screen reader text for nav element.
    Default: 'Posts navigation'

Default: posts navigation arguments

Code of get_the_posts_navigation: wp-includes/link-template.php VER 4.9.8

<?php
function get_the_posts_navigation( $args = array() ) {
	$navigation = '';

	// Don't print empty markup if there's only one page.
	if ( $GLOBALS['wp_query']->max_num_pages > 1 ) {
		$args = wp_parse_args( $args, array(
			'prev_text'          => __( 'Older posts' ),
			'next_text'          => __( 'Newer posts' ),
			'screen_reader_text' => __( 'Posts navigation' ),
		) );

		$next_link = get_previous_posts_link( $args['next_text'] );
		$prev_link = get_next_posts_link( $args['prev_text'] );

		if ( $prev_link ) {
			$navigation .= '<div class="nav-previous">' . $prev_link . '</div>';
		}

		if ( $next_link ) {
			$navigation .= '<div class="nav-next">' . $next_link . '</div>';
		}

		$navigation = _navigation_markup( $navigation, 'posts-navigation', $args['screen_reader_text'] );
	}

	return $navigation;
}

Related Functions

From tag: Navigation pagination

More from category: Menu

No comments
    Hello, !     Log In . Register