Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8986601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:35:20+00:00 2026-06-15T21:35:20+00:00

I have created two loops with pagination (first loop loops through CAT’S category and

  • 0

I have created two loops with pagination (first loop loops through CAT’S category and second loops through DOG’S category), but now I am stuck:(

The problem: After I click “Next entry” on my site (CAT’S category) it goes to second entry in that category BUT it also goes to my DOG’S category second entry (I don’t want THAT!! ). It also happens vice versa…

What I like to do is this: I click on “Next Entry” on my CAT’S category and it goes only to next post in THAT category (CAT’S) but NOT to second post in my DOG’S category, or another way around: I click on “Next Entry” on my DOG’S category and it goes only to next post in THAT category (DOG’S) but NOT to second post in my CAT’S category .

Can someone help me please? I have asked for help on
wordpress.stackexchange.com a while ago but I didn’t get any answer so I am asking question here.

Index php looks like this:

<?php get_header(); ?>
<?php get_sidebar(); ?>
<div id="blog">         
    <?php         
    $args = array(
    'category_name' => 'cats' 
    );
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $the_query = new WP_query($args . '&paged=' . $paged . '&cat=-3');      
    while( $the_query -> have_posts()) : $the_query -> the_post();              
    ?>

    <div class="post">
    <div class="post_title">
    <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
    </div>
        <div class="entry"> 
            <?php the_post_thumbnail(); ?>
            <?php the_content('Read on...'); ?>

            <p class="postmetadata">
            <?php _e('Filed under&#58;'); ?> <?php the_category(', ') ?> <?php _e('by'); ?> <?php  the_author(); ?><br />
            <?php comments_popup_link('No Comments &#187;', '1 Comment &#187;', '% Comments &#187;'); ?> <?php edit_post_link('Edit', ' &#124; ', ''); ?>
            </p>
        </div>
    </div>

    <?php endwhile;?>
    <?php wp_reset_postdata();?>
    <div class="navigation">
    <div style="float:left;" class="alignleft"><?php previous_posts_link('&laquo; Previous Entries') ?></div>
    <div style="float:right;" class="alignright"><?php next_posts_link('Next Entries &raquo;',$the_query->max_num_pages) ?></div>
    </div>      
    </div>

    <div id="blogs">    
    <?php       
    $args = array(
    'category_name' => 'dogs' 
    );
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $the_query = new WP_query($args . '&paged=' . $paged . '&cat=-10');
    while( $the_query -> have_posts()) : $the_query -> the_post();              
    ?>

    <div class="post">
    <div class="post_title">
    <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
    </div>
        <div class="entry"> 
            <?php the_post_thumbnail(); ?>
            <?php the_content('Read on...'); ?>

            <p class="postmetadata">
            <?php _e('Filed under&#58;'); ?> <?php the_category(', ') ?> <?php _e('by'); ?> <?php  the_author(); ?><br />
            <?php comments_popup_link('No Comments &#187;', '1 Comment &#187;', '% Comments &#187;'); ?> <?php edit_post_link('Edit', ' &#124; ', ''); ?>
            </p>

        </div>
    </div>

    <?php endwhile;?>
    <?php wp_reset_postdata();?>
    <div class="navigation">
    <div style="float:left;" class="alignleft"><?php previous_posts_link('&laquo; Previous Entries') ?></div>
    <div style="float:right;" class="alignright"><?php next_posts_link('Next Entries &raquo;',$the_query->max_num_pages) ?></div>
    </div>
    </div>
   <?php get_footer(); ?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T21:35:21+00:00Added an answer on June 15, 2026 at 9:35 pm

    You need 2 different paging values so add some new ones and rewrite rules which look for them (they’re really just to make the urls neater looking). The rewrite rules and the pagination link format mean you can page through one category while the other category page doesn’t change.

    In functions.php:

    function add_new_rules()
    {
      // new 'paged' variables
      global $wp;
      $wp->add_query_var('paged_cats');
      $wp->add_query_var('paged_dogs');
    
      // rewrite rules
      add_rewrite_rule('page/cats/(\d+)/dogs/(\d+)', 'index.php?paged_cats=$matches[1]&paged_dogs=$matches[2]', 'top');
      add_rewrite_rule('page/cats/(\d+)/dogs/?$', 'index.php?paged_cats=$matches[1]&paged_dogs=1', 'top');
    
      if( !array_key_exists('page/cats/(\d+)/dogs/(\d+)', (array)get_option('rewrite_rules')) )
      {
        global $wp_rewrite;
        $wp_rewrite->flush_rules();
      }
    }
    add_filter('init', 'add_new_rules');
    

    Check for the new query vars in index.php and use them for each WP_Query and the related pagination links.

    <div id="blog">
      <?php
      $paged_cats = (get_query_var('paged_cats')) ? get_query_var('paged_cats') : 1;
      $paged_dogs = (get_query_var('paged_dogs')) ? get_query_var('paged_dogs') : 1;
    
      $cats = new WP_query(array(
        'category_name' => 'cats',
        'paged' => $paged_cats,
        'posts_per_page' => 1
      ));
      while( $cats->have_posts() ) : $cats->the_post();
        ?>
        <div class="post">
          <div class="post_title">
            <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
          </div>
          <div class="entry">
            <?php the_post_thumbnail(); ?>
            <?php the_content('Read on...'); ?>
            <p class="postmetadata">
              <?php _e('Filed under&#58;'); ?> <?php the_category(', ') ?> <?php _e('by'); ?> <?php the_author(); ?><br />
              <?php comments_popup_link('No Comments &#187;', '1 Comment &#187;', '% Comments &#187;'); ?> <?php edit_post_link('Edit', ' &#124; ', ''); ?>
            </p>
          </div>
        </div>
      <?php endwhile; ?>
      <?php wp_reset_postdata(); ?>
      <?php if ( $cats->max_num_pages > 1 ) : ?>
      <div class="navigation">
        <?php
        echo paginate_links(array(
          'base' => home_url("page/cats/%#%/dogs/{$paged_dogs}"),
          'format' => '%#%',
          'current' => $paged_cats,
          'total' => $cats->max_num_pages,
        ));
        ?>
      </div>
      <?php endif; ?>
    </div>
    
      <hr>
    
    <div id="blogs">
      <?php
      $dogs = new WP_query(array(
        'category_name' => 'dogs',
        'paged' => $paged_dogs,
        'posts_per_page' => 1
      ));
      while( $dogs->have_posts() ) : $dogs->the_post();
        ?>
        <div class="post">
          <div class="post_title">
            <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
          </div>
          <div class="entry">
            <?php the_post_thumbnail(); ?>
            <?php the_content('Read on...'); ?>
            <p class="postmetadata">
              <?php _e('Filed under&#58;'); ?> <?php the_category(', ') ?> <?php _e('by'); ?> <?php  the_author(); ?><br />
              <?php comments_popup_link('No Comments &#187;', '1 Comment &#187;', '% Comments &#187;'); ?> <?php edit_post_link('Edit', ' &#124; ', ''); ?>
            </p>
          </div>
        </div>
      <?php endwhile;?>
      <?php wp_reset_postdata();?>
      <?php if ( $dogs->max_num_pages > 1 ) : ?>
      <div class="navigation">
        <?php
        echo paginate_links(array(
          'base' => home_url("page/cats/{$paged_cats}/dogs/%_%"),
          'format' => '%#%',
          'current' => $paged_dogs,
          'total' => $dogs->max_num_pages,
        ));
        ?>
      </div>
      <?php endif; ?>
    </div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created stopwatch which consist of two classes. First is stopwatchModel. Second is
I have created two DbContexts, one is for application configuration, the second is for
I have created two functions that sorts a list using bubble sort, but I
I have created two views on a FrameLayout, and requested focus to second. When
I have created two imageViews promatically as shown below: public void createImageViews(Integer count){ ImageView[]
I have created two WindowSurface (WPF), and I want to navigate betwen them. I've
I have created two tables & inserted values as shown below . Table 1
I have created two Pages Page1.xaml and Page2.xaml in windows8 metro apps. I have
I have created two folders layout and layout-land with two xml files, one for
I have created two forms in my Windows Application. One Form acts as a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.