Title: Pagination problem after adding query
Last modified: August 21, 2016

---

# Pagination problem after adding query

 *  [CissyH](https://wordpress.org/support/users/cissyh/)
 * (@cissyh)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/pagination-problem-after-adding-query/)
 * My client wants only the most recent blog to show on a specific category page,
   with sidebar links to older entries. I tried to handle this by adding a query
   to a custom category.php page (category-lakewatch.php) in my child theme. That
   worked fine as far as showing only one post, but then the “older posts” link 
   at the bottom began returning a 404 message. I removed my customization and re-
   checked the page to make sure that was the cause of the error, and pagination
   worked fine without the query.
 * My initial change to category-lakewatch.php was to add
 *     ```
       <?php query_posts( array ( 'category_name' => 'lakewatch', 'posts_per_page' => 1 ) ); ?>
       ```
   
 * just before
 *     ```
       <?php if ( have_posts() ) : ?>
       ```
   
 * on line 15 of category.php
 * I read the documentation [here ](http://codex.wordpress.org/Pagination#Troubleshooting_Broken_Pagination)
   which discussed pagination problems that could occur when adding a query then
   and tried these two suggested variations:
 *     ```
       <?php
       $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
       $args = array(
       'category_name' => 'lakewatch', 'posts_per_page' => 1
         'paged' => $paged
       );
       ?>
       ```
   
 *     ```
       <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts( array ( 'category_name' => 'lakewatch', 'posts_per_page' => 1 ) ); ?>
       ```
   
 * Both of them worked in as far as the page continued to show a single blog entry
   but in both cases I’m still getting a 404 when I click “older posts” at the bottom
   of the page.
 * You can see the page in question [here ](http://www.janetchapman.com/category/lakewatch/)
   if it helps.
 * If someone could point out where I’m going wrong, I’d really appreciate it. Thanks
   in advance

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Moderator [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/pagination-problem-after-adding-query/#post-3676172)
 * Try it without the query_posts in the template and with this in your theme’s 
   functions.php:
 *     ```
       function lakewatch_query( $query ) {
       	// not an admin page and is the main query
       	if ( !is_admin() && $query->is_main_query() ) {
       		// query for category 'lakewatch'
       		if ( is_category( 'lakewatch' ) ) {
   
       			$query->set( 'posts_per_page', 1 );
   
       		}
       	}
       }
       add_action( 'pre_get_posts', 'lakewatch_query' );
       ```
   
 * [http://codex.wordpress.org/Pagination#Removing_query_posts_from_the_main_loop](http://codex.wordpress.org/Pagination#Removing_query_posts_from_the_main_loop)
 *  Thread Starter [CissyH](https://wordpress.org/support/users/cissyh/)
 * (@cissyh)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/pagination-problem-after-adding-query/#post-3676183)
 * That worked beautifully. Thank you very much!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Pagination problem after adding query’ is closed to new replies.

## Tags

 * [category](https://wordpress.org/support/topic-tag/category/)
 * [page of posts](https://wordpress.org/support/topic-tag/page-of-posts/)
 * [pagination](https://wordpress.org/support/topic-tag/pagination/)
 * [posts](https://wordpress.org/support/topic-tag/posts/)
 * [twenty eleven](https://wordpress.org/support/topic-tag/twenty-eleven/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [CissyH](https://wordpress.org/support/users/cissyh/)
 * Last activity: [13 years, 1 month ago](https://wordpress.org/support/topic/pagination-problem-after-adding-query/#post-3676183)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
