I’m not sure why the first page works but the second doesn’t, though this may be a hint toward the problem. Toward the bottom of the category template page you have the following:
if (function_exists(custom_pagination)) {
custom_pagination($custom_query->max_num_pages,"",$paged);
}
If you review the above, there is a variable called $custom_query
. This looks like it’s a WordPress query that should be able to have a max_numb_pages item inside it. The issue is $custom_query
doesn’t exist anywhere else on the page and doesn’t appear to be global. You should change it to reflect your query on the page, $post_query
. The updated code would look like this:
if (function_exists(custom_pagination)) {
custom_pagination($post_query->max_num_pages,"",$paged);
}
This should tell the pagination that there are a number of pages and possibly render the correct link.
Further, I would recommend you print_r
the output of $link
, $link_array
, $page
, and $paged
to determine if all of those variables are outputting the correct response.
$link = $_SERVER[HTTP_HOST] . $_SERVER[REQUEST_URI];
$link_array = explode("https://wordpress.stackexchange.com/",$link);
$page = $link_array[count($link_array)-2];
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
$args = array(
'post_type' => 'post',
'posts_per_page' => 4,
'paged' => $paged,
'category_name' => $page
);
print_r($link);
print_r($link_array);
print_r($page);
print_r($paged);
print_r($args);
In the case of $args
, make sure it’s telling WordPress the correct page in the paged
attribute.