get_the_posts_navigation()
Retrieve the navigation block to the next/previous set of posts. Used on archive pages (categories, tags).
Such links can be obtained using get_next_posts_link() and get_previous_posts_link() functions.
To get navigation links for a single post, use the_post_navigation().
Used By: the_posts_navigation()
No Hooks.
Return
String
. HTML code for the previous/next sets of posts.
Usage
get_the_posts_navigation( $args );
- $args(array)
Default empty array.
Default: posts navigation arguments
-
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 the nav element.
Default: 'Posts navigation' -
aria_label(string)
ARIA label text for the nav element.
Default: 'Posts' - class(string)
Custom class for the nav element.
Default: 'posts-navigation'
-
Examples
#1 Output links to the previous / next set of posts
the_posts_navigation( [ 'prev_text' => '← Prev', 'next_text' => 'Next →', 'screen_reader_text' => 'My navigation', ] );
<nav class="navigation posts-navigation" role="navigation"> <h2 class="screen-reader-text">My navigation</h2> <div class="nav-links"> <div class="nav-previous"> <a href="http://example.com/page/3/">← Prev</a> </div> <div class="nav-next"> <a href="http://example.com/">Next →</a> </div> </div> </nav>
Notes
- Global. WP_Query. $wp_query WordPress Query object.
Changelog
Since 4.1.0 | Introduced. |
Since 5.3.0 | Added the aria_label parameter. |
Since 5.5.0 | Added the class parameter. |