So I have a page where I want to list posts of specific category and numbered pagination based on that category. Listing posts was not a problem as I'm using Divi which does it easily. But pagination is not going along.
Assuming following scenario:
- Category name = Events
- No. of post in Events catyegory = 6
- Max post per page = 2
Expected output:
1 2 3 Next
Current output:
1 2 3 .. 6 Next
Basically it's showing all numbers i.e number of pagination blocks is equal to no. of posts in that category.
Code in fucntions.php for pagination
function myPagination($args = '')
{
if (!isset($args['category'])) {
return;
}
ob_start();
$cat_id = get_cat_ID($args['category']);
$mycats = get_categories("include=$cat_id");
$total = $mycats[0]->category_count;
/*only bother with the rest if we have more than 1 page!*/
if ($total > 1) {
/*get the current page*/
if (!$current_page = get_query_var('paged')) {
$current_page = 1;
}
/*structure of "format" depends on whether we're using pretty permalinks*/
if (get_option('permalink_structure')) {
$format = '&paged=%#%';
} else {
$format = 'page/%#%/';
}
$pagination = paginate_links(array(
'base' => get_pagenum_link(1) . '%_%',
'format' => $format,
'current' => $current_page,
'total' => $total,
'mid_size' => 3,
'type' => 'list',
'add_args' => $query_args
));
ob_end_clean();
return $pagination;
}
}
The issue I can think of is it's not taking max number of posts to show to create the page gaps.
Any help would be much appreciated.
Thank you,