WordPress.org

Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/get the posts pagination

Description

Returns a paginated navigation composed of page numbers linked to the next/previous set of posts if they exist. These functions are used for post listings (like index.php) or archives (like archives.php).

This function only returns the markup. To display it you must echo it or use the_posts_pagination().

If the post is not paginated it returns an empty string.

Usage

 <?php $pagination get_the_posts_pagination(); ?> 

Parameters

mid_size
(integer) (optional) How many numbers to either side of current page, but not including current page.
Default: 1
prev_text
(string) (optional) The previous page text. Works only if 'prev_next' argument is set to true.
Default: __( 'Previous' )
next_text
(string) (optional) The next page text. Works only if 'prev_next' argument is set to true.
Default: __( 'Next' )
screen_reader_text
(string) (optional) Text meant for screen readers. Defaults to 'Posts navigation'.
Default: __( 'Posts navigation' )

Examples

Returns Pagination with Additional Links

The following example returns the pagination with two page links before the current page and two page links after the current page.
<?php
$pagination 
get_the_posts_pagination( array(
    
'mid_size' => 2,
) );
?>

Displays Pagination with Alternative Prev/Next Text

The following snippet returns the pagination replacing Next with Older and Previous with Newer.
<?php
$pagination 
get_the_posts_pagination( array(
    
'mid_size' => 2,
    
'prev_text' => __'Newer''textdomain' ),
    
'next_text' => __'Older''textdomain' ),
) );
?>

Change Log

Related