Multiple Loop respecting the Navigation/Pagination.
-
hello guys,
First of all i anna say i’ve tried everything, nothing working, i really need help…
so i have two loops runnings, no problems so far, but the problem is the pagination, which is only determined by the second loop ‘posts_per_page’ argument, and not regarding the total number of posts in the page (fist loop + second loop),so on the first page i have the posts wich are in the first loop and the 5 first posts of the second loop, so can be 9 in total,
and then on second page i have 5 post in total, etc….
My code :<?php $currentid = get_query_var('cat'); $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; /* Start loop */ if ( $paged < 2 ) : $query_city = new WP_Query('cat='.$currentid.'&category_name=cidades&paged='.$paged); while ($query_city->have_posts()) : $query_city->the_post(); ?> <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>> <div class="entry-content"> <?php echo get_the_post_thumbnail($page->ID, 'tumb-post'); ?> <header> <h5><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h5> <?php if($currentid == 7){roots_entry_meta();} ?> </header> <?php if (is_archive() || is_search()) { ?> <?php the_excerpt(); ?> <?php } else { ?> <?php the_content(); ?> <?php } ?> </div> <footer> </footer> <?php roots_post_inside_after(); ?> </article> <?php roots_post_after(); ?> <?php endwhile; ?> <?php endif; ?> <?php $temp = $wp_query; $wp_query= null; $wp_query = new WP_Query(); $wp_query->query('cat='.$currentid.',-61&paged='.$paged.'&posts_per_page='.$post_per_page); if ($wp_query->have_posts()) : while ($wp_query->have_posts()) : $wp_query->the_post(); ?> <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>> <div class="entry-content"> <?php echo get_the_post_thumbnail($page->ID, 'tumb-post'); ?> <header> <h5><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h5> <?php if($currentid == 7){roots_entry_meta();} ?> </header> <?php the_excerpt(); ?> </div> <footer> </footer> <?php roots_post_inside_after(); ?> </article> <?php endwhile; endif; /* End loop */ ?> <?php /* Display navigation to next/previous pages when applicable */ ?> <nav id="post-nav" class="pager"> <div class="previous"><?php next_posts_link(__('← Older posts', 'roots')); ?></div> <div class="next"><?php previous_posts_link(__('Newer posts →', 'roots')); ?></div> </nav> <?php $wp_query = null; $wp_query = $temp;?>
so the problem is that the first page contain X posts from first query and then 5 posts,(for ex 9 in total) but i want to have 5 posts in total on every page, even the first page!!
the option posts_per_page is determined in each query, i dont know how to keep this option for the total of posts on the page,
i have tried to change this option depending on the page like this$post_per_page = $paged==1 ? 1 : 5; $wp_query->query('cat='.$currentid.',-61&paged='.$paged.'&posts_per_page='.$post_per_page);
but it’s not working…
I really need help as im going crazy….
Thanks!!
- The topic ‘Multiple Loop respecting the Navigation/Pagination.’ is closed to new replies.