• Hello,
    I have a problem with pagination on my home page when the URL rewriting is turned on. I use static page as my home page with custom template.

    Here is my loop with pagination:

    <?php
    if ( get_query_var('paged') ) { $paged = get_query_var('paged'); }
    elseif ( get_query_var('page') ) { $paged = get_query_var('page'); }
    else { $paged = 1; }
    query_posts('cat=1&posts_per_page=12&paged=' . $paged);
    ?>
    
    <?php if ( have_posts() ) : while (have_posts()) : the_post(); ?>
    <-- THE LOOP CONTENT -->
    <?php endwhile; the_posts_pagination( array(
    	'mid_size'  => 5,
    	'prev_text' => __( '', 'textdomain' ),
    	'next_text' => __( '', 'textdomain' ),
    ) );
    else : ?>
    <!-- No posts found -->
    <?php endif; ?>

    I have already tried to add_rewrite_rule into functions.php, which looked like this:

    function plugin_name_add_rewrite_rules() {
      add_rewrite_rule('page/([0-9]+)?', 'index.php?paged=$matches[1]', 'top');
    }
    add_filter('init', 'plugin_name_add_rewrite_rules');

    But it didn’t worked for me.

    When URL rewriting is turned on and I click on the pagination’s page number (for example: mydomain.com/page/2/) the page is just reloaded and I’m still on my home page. When I paste manually address mydomain.com/?paged=2 into my browser everything is OK – I’m on the second page of pagination.

    Has anyone got an idea what am I doing wrong? Please help.

  • The topic ‘Pagination & URL rewriting not working’ is closed to new replies.