Languages: English • 한국어 • 日本語 (Add your language)
Prints a link to the next set of posts within the current query.
If you need the values for use in PHP, use get_next_posts_link().
Because post queries are usually sorted in reverse chronological order, next_posts_link() usually points to older entries (toward the end of the set) and previous_posts_link() usually points to newer entries (toward the beginning of the set).
<?php next_posts_link( $label , $max_pages ); ?>
<?php next_posts_link(); ?>
<?php next_posts_link( 'Older Entries »', 0 ); ?>
<?php if( get_next_posts_link() ) : next_posts_link( 'Older Entries »', 0 ); endif; ?>
Add the $max_pages parameter to the next_posts_link() function when querying the loop with WP_Query. To get the total amount of pages you can use the 'max_num_pages' property of the custom WP_Query object.
<?php // set the "paged" parameter (use 'page' if the query is on a static front page) $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1; // the query $the_query = new WP_Query( 'cat=1&paged=' . $paged ); ?> <?php if ( $the_query->have_posts() ) : ?> <?php // the loop while ( $the_query->have_posts() ) : $the_query->the_post(); ?> <?php the_title(); ?> <?php endwhile; ?> <?php // next_posts_link() usage with max_num_pages next_posts_link( 'Older Entries', $the_query->max_num_pages ); previous_posts_link( 'Newer Entries' ); ?> <?php // clean up after the query and pagination wp_reset_postdata(); ?> <?php else: ?> <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p> <?php endif; ?>
Since: 0.71
next_posts_link() is located in wp-includes/link-template.php
.