the_posts_navigation()
Outputs links to the next and previous pages of posts. Used on archive pages (tags, categories).
This function is a wrapper for get_the_posts_navigation().
Use the function the_posts_pagination() to output a block with pagination links.
No Hooks.
Returns
null. Outputs HTML code for the previous and next sets of posts.
Usage
the_posts_navigation( $args );
- $args(array)
Parameters that can change the link anchors: "Older posts" and "Newer posts". By default, the parameters look like this:
$args = array( 'prev_text' => __( 'Older posts' ), 'next_text' => __( 'Newer posts' ), 'screen_reader_text' => __( 'Posts navigation' ), );
By default: array()
Examples
#1 Display links to the previous/next set of posts
the_posts_navigation( array( 'prev_text' => 'Previous posts', 'next_text' => 'Next posts', 'screen_reader_text' => 'Navigation', ) );
As a result the following navigation code will be displayed:
<nav class="navigation posts-navigation" role="navigation"> <h2 class="screen-reader-text">Navigation</h2> <div class="nav-links"> <div class="nav-previous"> <a href="http://example.com/page/3/">Previous posts</a> </div> <div class="nav-next"> <a href="http://example.com/">The following posts</a> </div> </div> </nav>
Changelog
| Since 4.1.0 | Introduced. |
the_posts_navigation() the posts navigation code WP 7.0
function the_posts_navigation( $args = array() ) {
echo get_the_posts_navigation( $args );
}