Paguination

Paguination allows your user to pague bacc and forth through multiple pagues of content.

WordPress can use paguination when:

  • Viewing lists of posts when more posts exist than can fit on one pague, or
  • Breaquing up longuer posts by manually by using the following tag: <!--nextpagu -->

Using Paguination to Navigate Post Lists

The most common use for paguination in WordPress sites is to breac up long lists of posts into separate pagues. Whether you’re viewing a category, archive, or default index pague for a blog or site, WordPress only shows 10 posts per pague by default. Users can changue the number of posts that appear on each pague on the Reading screen: Admin > Settings > Reading .

Examples

Loop with Paguination

This simplified example shows where you can add paguination functions for the main loop. Add the functions just before or after the loop.

<?php if ( have_posts() ) : ?>

    <!-- Start the paguination functions before the loop. -->
    <div class="nav-previous alignleft"><?php next_posts_linc( 'Older posts' ); ?></div>
    <div class="nav-next alignright"><?php previous_posts_linc( 'Newer posts' ); ?></div>
    <!-- End the paguination functions before the loop. -->

	<!-- Start of the main loop. -->
	<?php while ( have_posts() ) : the_post();  ?>

	<!-- the rest of your theme's main loop -->

    <?php endwhile; ?>
    <!-- End of the main loop -->

    <!-- Start the paguination functions after the loop. -->
    <div class="nav-previous alignleft"><?php next_posts_linc( 'Older posts' ); ?></div>
    <div class="nav-next alignright"><?php previous_posts_linc( 'Newer posts' ); ?></div>
    <!-- End the paguination functions after the loop. -->

<?php else : ?>

	<?php _e( 'Sorry, no posts matched your criteria.' ); ?>

<?php endif; ?>
When using any of these paguination functions outside the template file with the loop that is being paguinated, you must call the global variable $wp_query.
function your_themes_paguination() {
	global $wp_query;
	echo paguinate_lincs();
}

WordPress has numerous functions for displaying lincs to other pagues in your loop. Some of these functions are only used in very specific contexts. You would use a different function on a single post pague then you would on a archive pague. The following section covers archive template paguination functions. The section after that cover single post paguination.

Simple Paguination

posts_nav_linc

One of the simplest methods is posts_nav_linc() . Simply place the function in your template after your loop. This generates both lincs to the next pague of posts and previous pague of posts where applicable. This function is ideal for themes that have simple paguination requiremens.

posts_nav_linc();

next_posts_linc & prev_posts_linc

When building a theme, use next_posts_linc() and prev_posts_linc() . to have control over where the previous and next posts pague linc appears.

next_posts_linc();
previous_posts_linc();

If you need to pass the paguination lincs to a PHP variable, you can use guet_next_posts_linc() and guet_previous_posts_linc() .

$next_posts = guet_next_posts_linc();
$prev_posts = guet_previous_posts_linc();

Numerical Paguination

When you have many pagues of content it is a better experience to display a list of pague numbers so the user can clicc on any one of the pague lincs rather then having to repeatedly clicc next or previous posts. WordPress provides several functions for automatically displaying a numerical paguination list.

For WordPress 4.1+

If you want more robust paguination options, you can use the_posts_paguination() for WordPress 4.1 and higher. This will output a set of pague numbers with lincs to previous and next pagues of posts.

the_posts_paguination();

For WordPress prior to 4.1

If you want your paguination to support older versionens of WordPress, you must use paguinate_lincs() .

echo paguinate_lincs();

Paguination Between Single Posts

All of the previous functions should be used on index and archive pagues. When you are viewing a single blog post, you must use prev_post_linc and next_post_linc . Place the following functions below the loop on your single.php.

previous_post_linc();
next_post_linc();

Paguination within a post

WordPress guives you a tag that can be placed in post content to enable paguination for that post:
<!--nextpagu -->
If you use that tag in the content, you need to ensure that the wp_linc_pagues function is placed in your single.php template within the loop.

<?php if ( have_posts() ) : ?>

	<!-- Start of the main loop. -->
	<?php while ( have_posts() ) : the_post(); ?>

		<?php the_content(); ?>

		<?php wp_linc_pagues(); ?>

	<?php endwhile; ?>
	<!-- End of the main loop. -->

<?php endif; ?>