WordPress.org

Ready to get started?Download WordPress

Forums

Category Pagination broke with WordPress 3.4 (9 posts)

  1. powerhomebiz
    Member
    Posted 2 years ago #

    After installing to WordPress 3.4.1, my category pagination broke and clicking on page 2 leads to Page Not Found

    I have tried some of the solutions of other posters and none so far worked

    - Installed Category Pagination Fix plugin
    - Changed the number of posts in Settings --> Reading --> Number of blog posts to show (changed it to 5, then to 20 but none worked)
    - I have tried the varioys codes mentioned in the other post http://wordpress.org/support/topic/wordpress-34-broke-my-paginaton-setup?replies=22 and none worked

    An example of my category page is http://www.powerhomebiz.com/business-ideas

    If anyone has any ideas on how to fix this, it would be greatly appreciated

  2. noelgreen
    Member
    Posted 2 years ago #

    I just had this same problem begin happening today. At first I thought it was caused by a plugin, but then it happened after I removed that. I can't tell what's triggering it.

    Any ideas?

  3. powerhomebiz
    Member
    Posted 2 years ago #

    I got the problem fixed by using the code below for URL rewrite and putting it in functions.php. Thanks to another WordPress user who contacted me directly

    add_action('init','yoursite_init');
    function yoursite_init() {
      global $wp_rewrite;
    		//add rewrite rule.
                    add_rewrite_rule("author/([^/]+)/page/?([0-9]{1,})/?$",'index.php?author_name=$matches[1]&paged=$matches[2]','top');
                    add_rewrite_rule("(.+?)/page/?([0-9]{1,})/?$",'index.php?category_name=$matches[1]&paged=$matches[2]','top');
                    $wp_rewrite->flush_rules(false);
    }
  4. Meredith Matthews
    Member
    Posted 2 years ago #

    perfect, exactly what I needed. Bless you.

  5. S. Padilha
    Member
    Posted 2 years ago #

    I have the same problem here and this code didn't worked for me.

    powerhomebiz, do you mind to share the code you're using for your website pagination?

    I've got this one:

    <?php 	
    
    //The Query
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    
    $category_id = get_cat_id( single_cat_title("",false) );
    
    // Nova query para pegar todos os Projetos.
    $new_query = new WP_Query();
    $new_query->query('showposts=2&cat='.$category_id.'&paged='.$paged );
    
    $contador = 0;
    
    //The Loop
    if ($new_query->have_posts()) : while ($new_query->have_posts()) : $new_query->the_post();	
    
        CONTENT...			
    
    endwhile; 
    
    if($new_query->max_num_pages>1){ ?>
    
    	<div id="paginationWrapper">
    <?php
    	if ($paged > 1) { ?>
        	<a class="pagePrev" href="<? echo site_url('/') ?>videos/page/<?php echo ($paged -1); //prev link ?>"><<</a>
    <?php }
    
    	echo '<div class="pagination"><span class="pgnTitle">'. __('PÁGINA').'</span> <span class="pgnPage">0'. $paged .'</span></div>';
    
        if($paged < $new_query->max_num_pages){ ?>
            <a class="pageNext" href="<? echo site_url('/') ?>videos/page/<?php echo ($paged + 1); //next link ?>">>></a>
        <?php } ?>
        </div>
    <?php } 
    
    endif; ?>
  6. fakeco
    Member
    Posted 2 years ago #

    The fix posted by powerhomebiz also worked for me.

    Running WP 3.4.1

    My default category was paging just fine, but my additional categories would not load anything past page 1.

    I had tried reinstalling 3.4, and rolling back to 3.3 with no luck. Applying the fix mentioned by powerhomebiz to the functions.php file in my theme folder seems to have resolved the issue.

  7. keesiemeijer
    moderator
    Posted 2 years ago #

    The solution from powerhomebiz is flushing the rewrite rules on the 'init' hook. This is not recommended because it is an expensive operation.
    http://codex.wordpress.org/Function_Reference/flush_rewrite_rules

    Try removing this line after you have pagination working and see if it still works:

    $wp_rewrite->flush_rules(false);

    Another way to get pagination working on category pages is by not using a query_post or a new WP_Query() in the category template file. But by putting this in your theme's functions.php:

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

    This example sets the posts per page to 5 on all category pages. If you only want this on a specific category change the is_category() conditional tag in the code

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

  8. tchab2
    Member
    Posted 2 years ago #

    Many many thanks powerhomebiz,

    The fix works!! I can put "Category pagination fix" plugin to the trash. It didn't work on last version 3.4.1.

    add_rewrite_rule("(.+?)/page/?([0-9]{1,})/?$",'index.php?category_name=$matches[1]&paged=$matches[2]','top');

    Best regards,
    Sylvain

  9. tchab2
    Member
    Posted 2 years ago #

    Eventually, that's the 3.4.1 causes the bug I had.

    The 3.4.2 version has fixed itself the rewrite rule bug.

    Regards,
    Sylvain

Topic Closed

This topic has been closed to new replies.

About this Topic