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)."'>&laquo;</a>";
         if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'>&lsaquo;</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)."'>&rsaquo;</a>";  
         if ($paged < $pages-1 &&  $paged+$range-1 < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($pages)."'>&raquo;</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.

link|improve this question

don't you need to use wp_reset_postdata(); at the end of the loop function ? – Simon Jan 26 at 22:40
I have had wp_reset_query(); at the end of the endif. I tried add wp_reset_postdata(); also, but that didn't seem to change anything. – MotiveKyle Jan 27 at 18:15
I am starting to think that since it's category-slug.php, it checks to see if the page (3,4 5, etc) exists before anything runs on the page, and since they don't, it returns a 404 before my query goes. Any ideas on how I can make it not do that? Something in functions.php I can add? – MotiveKyle Jan 27 at 18:17
Did you try without customizing pagination and just use WP built-in pagination ? Or some plugin like wp_navi ? – Simon Jan 29 at 10:22
feedback

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
or
required, but never shown

Browse other questions tagged or ask your own question.