Title: Pagination and variable category
Last modified: August 20, 2016

---

# Pagination and variable category

 *  [DEKL1NE](https://wordpress.org/support/users/dekl1ne/)
 * (@dekl1ne)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/pagination-and-variable-category/)
 * I’m trying to use links to display one of 2 categories on my page by using ?cat
   =15 or ?cat=4 as a filter, but the problem here is that my pagination also needs
   to know what category is currently active.
 * below is the loop I’m using:
 *     ```
       <?php global $more;?>
       <?php
       // get the category ID
       $cat_obj = $wp_query->get_queried_object();
       $cat_ID = $cat_obj->term_id;
   
       global $wp_query;
       $args=array(
             'showposts' => 6,
             'cat' => $cat_ID,
   
       );
       $query = new WP_Query( $args );
       $total_pages = $query->max_num_pages;
       if ($total_pages > 1){
       echo '<div id="pagination">';
         $current_page = max(1, get_query_var('paged'));
         echo paginate_links(array(
             'base' => get_pagenum_link(1) . '%_%',
             'format' => '?paged=%#%',
             'current' => $current_page,
             'total' => $total_pages,
           ));
       }
       echo '</div>'
       ?>
       <?php query_posts ($query_string . ''); ?>
       	<?php if ( have_posts() ) : ?>
           <?php while ( have_posts() ) : the_post(); ?>
           <ul id="cms-column" class="item">
             <li id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
               <div class="post-header">
                  <h2><?php the_title(); ?></h2>
               </div><!--end post header-->
               <div class="entry clear">
                   <?php if ( function_exists( 'add_theme_support' ) ) the_post_thumbnail('bigger_image'); ?>
                   <div class="date"><?php the_time( 'j M y' ); ?></div>
       			<?php $more = 0;the_content(__('Read More &darr;', 'TRUE')); ?>
                   <?php edit_post_link(); ?>
                   <?php wp_link_pages(); ?>
               </div><!--end entry-->
               <div class="post-footer">
               </div><!--end post footer-->
             	</li><!--end post-->
             </ul>
           <?php endwhile; /* rewind or continue if all posts have been fetched */ ?>
           <div id="clear">
           </div>
           <?php else : ?>
           <?php endif; ?>
       ```
   

The topic ‘Pagination and variable category’ is closed to new replies.

## Tags

 * [category](https://wordpress.org/support/topic-tag/category/)
 * [pagination](https://wordpress.org/support/topic-tag/pagination/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [DEKL1NE](https://wordpress.org/support/users/dekl1ne/)
 * Last activity: [13 years, 5 months ago](https://wordpress.org/support/topic/pagination-and-variable-category/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
