
How to Include Numeric Pagination in WordPress
- June 3, 2016
- Leave a comment
Incorporating numeric pagination within WordPress is a process that is deemed problematic by many developers throughout the globe. Majority of these developers tend to use custom functions in order to create numeric pagination. However, functions within WordPress core such as paginate_links can also be used.
paginate_links is a function that can be used within the bounds of any WordPress query to include numeric pagination. The default function is as follows:
1 |
<?php echo paginate_links( $args ) ?> |
The $args is an optional array consisting of certain parameters that are used to regulate the output of a function. The whole argument array is also optional however the function will yield nothing unless certain arguments are setup. The list of arguments is given below:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<?php $args = array( 'base' => '%_%', // Used to reference URL , which will create the paginate links 'format' => '?paged=%#%', // User to create pagination structure 'total' => 1, // The total number of pages 'current' => 0, // Current Page 'show_all' => false, // Whether to show all pages, 'end_size' => 1, // How many pages to show on start or end of the list 'mid_size' => 2, // How many pages to show around current page 'prev_next' => true, // Whether to show the next and previous links 'prev_text' => __('« Previous'), // Previous link text 'next_text' => __('Next »'), // Next link text 'type' => 'plain', // Format to return “Plain”, “Array” or “List” 'add_args' => false, // Array of optional query arguments 'add_fragment' => '', // String to append to each link 'before_page_number' => '', // Text to add before page number 'after_page_number' => '' // Text to add after page number ); ?> |
The arguments that are essential to generate pagination using this function are total and current. These are set according to the current query.
For instance, the following code can be used for any WordPress Default Query such as search results, archives, etc.
1 2 3 4 5 6 7 8 9 10 |
<?php global $wp_query; $big = 999999999; echo paginate_links( array( 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), 'format' => '?paged=%#%', 'current' => max( 1, get_query_var('paged') ), 'total' => $wp_query->max_num_pages ) ); ?> |
Hi dude, i have also find out one good example
Numeric Pagination WordPress