I have a custom template category.php and i have added following code for pagination but it does not work. When I click the next page button it goes to 404 error page and link looks like this: ../mythemedir/cat=x&page=1&paged=2 404 error page after click the next button and link: mythemedir/cat=x&page=1&paged=2 But when i type the address manually in the address bar: ../mythemedir/cat=x&page=2 everything is ok but the link of "Previous" button is mythemedir/cat=x&page=2
After type the adress manually i got a my second page but previous button didn't work What should I do for fix it?
This is my code on my page:
<?php global $paged;
$paged = ( get_query_var('page') ) ? get_query_var('page') : 1;
$query = new WP_Query (array(
'posts_per_page' => 3,
'cat' => '2, 30',
'lang' => pll_current_language(),
'paged' => $paged
));
while($query->have_posts()) :
$query->the_post();
?>
// Loop content
<?php endwhile ?>
This is my code on my page for navigation:
<?php if (function_exists("pagination")) {
pagination($query->max_num_pages,"",$paged);
} ?>
This is my code in my functions.php file:
function pagination($pages = '', $range = 4)
{
$showitems = ($range * 2)+1;
global $paged;
if(empty($paged)) $paged = 1;
if($pages == '')
{
global $wp_query;
$pages = $wp_query->max_num_pages;
if(!$pages)
{
$pages = 1;
}
}
if(1 != $pages)
{
echo "<div class=\"pagination\"><span>Page ".$paged." of ".$pages."</span>";
if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link(1)."'>« First</a>";
if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'>‹ Previous</a>";
for ($i=1; $i <= $pages; $i++)
{
if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
{
echo ($paged == $i)? "<span class=\"current\">".$i."</span>":"<a href='".get_pagenum_link($i)."' class=\"inactive\">".$i."</a>";
}
}
if ($paged < $pages && $showitems < $pages) echo "<a href=\"".get_pagenum_link($paged + 1)."\">Next ›</a>";
if ($paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($pages)."'>Last »</a>";
echo "</div>
";
}
}