• I’m working on a pagination option for my tag and categories templates but I can’t figure it out. I’m assuming it’s an argument that I’m missing but I have tried to the extent of my knowledge and am getting bored of Googling around/trial and error.

    My url format is currently:
    http://xxx.com/?tag=developed
    http://xxx.com/?tag=developed&paged=2

    My pagination code is:

    $wp_query->query('showposts=2'.'&paged='.$paged.'&tag='.$tag.'');

    echo paginate_links( array(
    	'base' => str_replace( $big, '%#%', get_pagenum_link( $big ) ),
    	'format' => '?paged=%#%',
    	'current' => max( 1, get_query_var('paged') ),
    	'total' => $wp_query->max_num_pages,
    	'prev_text'    => __('Previous'),
    	'next_text'    => __('Next'),
    	'type'         => 'list'
    ) );

    This doesn’t work on the category index either, but the code is the same for my blog index and the pagination does work there. Any support is appreciated

    -Jake

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    Remove the query in your tag and category template file, use a normal loop and try it with this in your theme’s functions.php:

    function my_post_queries( $query ) {
    
      // not an admin page and it is the main (paginated) query
      if (!is_admin() && $query->is_main_query()){
    
        // for tags
        if(is_tag()){
    
          // set the posts_per_page here
          $query->set('posts_per_page', 2);
    
        }
    
        // for categories
        if(is_category()){
          $query->set('posts_per_page', 2);
        }
    
      }
    }
    add_action( 'pre_get_posts', 'my_post_queries' );

    And put global $wp_query; before your pagination code.

    This will set the posts per page on all tag and category pages to 2.

    Thread Starter Crayz

    (@crayz)

    I appreciate the speedy response, applied the new code now the pagination works great.

    Thanks!

    Moderator keesiemeijer

    (@keesiemeijer)

    You’re welcome. I’m glad you got it resolved 🙂

    If you don’t have a static front page you could use this for your home page as wel:

    // for the home page
    if(is_home()){
      $query->set('posts_per_page', 2);
    }

    This method of querying is better and faster than a query_posts() or new WP_Query() on the main loop (you want to paginate). Read here why:

    http://www.billerickson.net/customize-the-wordpress-query/
    http://developer.wordpress.com/2012/05/14/querying-posts-without-query_posts/

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘WordPress Pagination on Tags Template’ is closed to new replies.