posts_nav_link()
Displays the post pages link navigation for previous and next pages.
Uses: get_posts_nav_link()
No Hooks.
Return
null
. Nothing (null).
Usage
posts_nav_link( $sep, $prelabel, $nxtlabel );
- $sep(string)
- Separator for posts navigation links.
Default: '' - $prelabel(string)
- Label for previous pages.
Default: '' - $nxtlabel(string)
- Optional Label for next pages.
Default: ''
Examples
#1 HTML that the function outputs
<?php posts_nav_link( $sep, $prelabel, $nextlabel ); ?>
It will:
<a href="link">« Previous page</a> — <a href="link">Next page »</a>
#2 To center it (show it in the middle of the page) use this code:
<div style="text-align:center;"> <?php posts_nav_link(' - ', 'Previous page', 'Next page'); ?> </div>
#3 As anchors links can use pictures, such as this:
<?php posts_nav_link( ' ', '<img src="' . get_stylesheet_directory_uri() . '/images/prev.jpg" />', '<img src="' . get_stylesheet_directory_uri() . '/images/next.jpg" />' ); ?>
#4 An alternative to this function
In some cases it's better to use two functions: previous_posts_link() and next_posts_link():
<div class="navigation"> <div class="alignleft"><?php previous_posts_link( '« Previous Entries' ); ?></div> <div class="alignright"><?php next_posts_link( 'Next Entries »', '' ); ?></div> </div>
Changelog
Since 0.71 | Introduced. |
posts_nav_link() posts nav link code WP 6.8
function posts_nav_link( $sep = '', $prelabel = '', $nxtlabel = '' ) { $args = array_filter( compact( 'sep', 'prelabel', 'nxtlabel' ) ); echo get_posts_nav_link( $args ); }