Support » Fixing WordPress » Pagination issues with category.php

  • Resolved 916VT


    Hi there,

    I get some issues with my category.php template. Pagination goes to 404 error.

    I read douzen of tutorials and codex pages but I can not see where it comes from.

    Here is my code :

    <?php get_header(); ?>
    	<div class="cat-blog wrap space">
    			<h1 class="page-title">Blog</h1>
    			  <?php if(have_posts()) : query_posts($query_string.'&category_name=blog&posts_per_page=2'); while (have_posts()) : the_post(); ?>
    				<article <?php post_class(); ?> >
    					<a href="<?php the_permalink() ?>">
    					  	<?php the_title(); ?>
    			  <?php endwhile; ?>
    			  <?php endif; ?>
    				<div class="navigation">
    					  global $wp_query;
    					  $big = 999999999; // need an unlikely integer
    					  echo paginate_links( array(
    						  'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
    						  'format' 		=> '?paged=%#%',
    						  'prev_next'   => false,
    						  'current' 	=> max( 1, get_query_var('paged') ),
    						  'total' 		=> $wp_query->max_num_pages
    					  ) );
    				<ul id='postPagination'>
    					<li class=""><?php previous_posts_link('&laquo;&laquo;') ?></li>
    					<li class=""><?php next_posts_link('&raquo;&raquo;') ?></li>
    		  <div class="clear"></div>
    <?php get_footer(); ?>

    If someone has any idea to fix it… Any help is welcome 🙂
    Thanks a lot

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



    If this is in category.php all your category pages will only have posts from the category “blog”. Is this what you want?

    Hi keesiemeijer,

    Yes, I would like to have all ‘blog’ posts but, displayed by 5 per page (I set 2 only for trying pagination).

    BTW – I now set this template as category-blog.php but it’s still not working…

    I’m trying the different points from the link you sent but that’s a bit too much of php for me…

    Hi there,

    Finally, I added that part of code, from the link you sent, and adapted it and it works :

    function my_post_queries( $query ) {
      // do not alter the query on wp-admin pages and only alter it if it's the main query
      if (!is_admin() && $query->is_main_query()){
        // alter the query for the home and category pages
          $query->set('posts_per_page', 3);
          $query->set('posts_per_page', 3);
    add_action( 'pre_get_posts', 'my_post_queries' );

    I don’t know why but it works…

    Thanks a lot for helping !

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Pagination issues with category.php’ is closed to new replies.