I have a category with about 50 posts. I need to make more categories with the same exact posts in there for landing pages.
Instead of having to add all those games to the new categories, I have tried to just create a category-new-category-name.php file with a custom WP_Query that pulls from the original category instead of it's own.
So, Category 1 has all the posts I need, this is the query I have in the category-new-category-name.php file:
$args = array(
'post_type' => 'post',
'orderby' => 'menu_order',
'order' => 'ASC',
'posts_per_page' => 10,
'cat' => 1,
'paged' => $paged,
);
$my_query = new WP_Query($args);
When I run this, it shows the 5 pages in the pagination and even shows the correct posts up to a point.
If the new category only has 2 pages of posts in it, the query will show the 2 pages of the category I am pulling from, but will return a 404 for pages 3, 4, and 5.
If the new category has the same number of posts as the original, it will display them all correctly, but obviously this is counterproductive as I am trying to avoid filling the new categories.
This is the pagination function I am using and has worked up to this point:
function gp_pagination($pages = '', $range = 2)
{
$showitems = ($range * 2)+1;
global $paged;
if (get_query_var('paged')) {
$paged = get_query_var('paged');
} elseif (get_query_var('page')) {
$paged = get_query_var('page');
} else {
$paged = 1;
}
if($pages == '')
{
global $wp_query;
$pages = $wp_query->max_num_pages;
if(!$pages)
{
$pages = 1;
}
}
if(1 != $pages)
{
echo "<div class='wp-pagenavi'>";
echo '<span class="pages">'.__('Page', 'gp_lang').' '.$paged.' '.__('of', 'gp_lang').' '.$pages.'</span>';
if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link(1)."'>«</a>";
if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'>‹</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)."'>›</a>";
if ($paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($pages)."'>»</a>";
echo "</div>\n";
}
}
I have already fixed a similar issue where the pages were returning 404's because the posts_per_page was different from Wordpress' default. This seems to be unrelated.
The code I used to resolve that is:
function cure_wp_amnesia_on_query_string($query_string){
if (!is_admin() ){
if (isset($query_string['category_name']))
{
switch ($query_string['category_name']) {
case 'category-name':
$query_string['posts_per_page'] = 5;
break;
default:
$query_string['posts_per_page'] = 9;
break;
}
}
}
return $query_string;
}
This has me stumped for the last few days and I'd really appreciate any help.