...
Wordpress

How to use custom category pagination in wordpress?

31 December 2018

In this blog use a custom template page that is showing posts from a particular category and add some custom category pagination in WordPress.

Something like the following should work.

using the $paged attribute within the query as follows:

Example 1:

$paged = ( get_query_var('page') ) ? get_query_var('page') : 1;
$query_args = array(
  'post_type' => 'post',
  'category_name' => 'tutorials',
  'posts_per_page' => 5,
  'paged' => $paged
);

Example 2:

<?php
 global $wp_query;
 $big = 999999999; // need an unlikely integer
 echo $paginate_links = paginate_links(array(
                'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
                'format' => '?paged=%#%',
                'current' => max(1, get_query_var('paged')), // use a paged attribute
                'total' => $wp_query->max_num_pages,
                'prev_next' => false,
                'end_size' => 9,
            ));
            wp_reset_query();
            ?>
Output here:

custom category pagination

Leave a Comments