Pagination issues with category.php
-
Hi everyone,
I am developing a site using a child of twentyeleven, which use a custom post type called ‘product’. The site has a category named ‘Products’ which has many child categories such as Product1, Product2 etc.
I have included a ‘Products’ menu item. When clicked, a page is loaded that lists all the child categories of category ‘Product’, which I have implemented using category-products. When one of these is clicked (as an example ‘Product1’) I want to display all the titles and permalinks of any custom post type ‘product’. Because I use customised php files for everything else, I figured I could use category.php to display these.
And it works, except for the occasions where the number of products in a child category exceeds the posts_per_page limit. When that happens, the navigation to next page is displayed, but when clicked, it cannot find any posts – displaying the ‘This is somewhat embarrassing isn’t it’ message that is twenty eleven’s default.
The code for category.php:
category = get_category( get_query_var( 'cat' ) ); $thiscat = $category->cat_ID; $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $args = array('post_type' => 'product', 'paged' => $paged, 'posts_per_page'=>2, 'cat' => $thiscat ); $wp_query = new WP_Query($args); if ($wp_query->have_posts () ): while($wp_query->have_posts() ): //html to display title and permalink endwhile next_posts_link('? Go to next page...'); previous_posts_link('Go to previous page...');
For example, if under child category Product1 I have 4 posts, the first two posts display correctly with a ‘Go to next page’ link on this url: ../category/products/product_1/. When this link is pressed I get the ’embarrassing’ message on this url: ../category/products/product_1/page/2/
Can anyone help me solve this?
- The topic ‘Pagination issues with category.php’ is closed to new replies.