I have already read some info about his issue on the web, but I had no serious solution.
Resources I read:
http://codex.wordpress.org/The_Loop#Multiple_Loops_in_Action
http://wordpress.org/support/topic/next_posts_link-not-displays-same-posts-not-next-posts-when-using-offset – Exactly the same problem.
Now here is my code in index.php:
<!--slider-->
<div id="featured">
<?php
// query the posts of your custom post types
query_posts('posts_per_page=5');
if (have_posts()) : while (have_posts()) : the_post(); ?>
<!--main body-->
<?php
// query the posts of your custom post types
query_posts('posts_per_page=5&offset=5');
if (have_posts()) : while (have_posts()) : the_post(); ?>
When I press the next posts I get the same duplicates of the body posts.
What is the solution for this?
EDIT:
I have wrote new code:
// featured
$slider = new WP_Query(array('posts_per_page' => 5));
if ($slider->have_posts()) : while ($slider->have_posts()) : $slider->the_post();
//main:
$p = get_query_var('paged');
if($p >0){
$main = new WP_Query(array('posts_per_page' => 5, 'paged'=>get_query_var('paged')));
}else{
$main = new WP_Query(array('posts_per_page' => 5, 'offset' => 5,'paged'=>get_query_var('paged')));
}
if ($main->have_posts()) : while ($main->have_posts()) : $main->the_post();
//navigation:
<div class="navigation" >
<div class="next-posts"><div class="nextBtn2"><?php previous_posts_link(); ?></div></div>
<div class="prev-posts"><?php next_posts_link(); ?></div>
</div>
You should WP_Query for secondary loop (the featured) and use query_posts for the main body.
It works 95%
it will break on the last page because it will try to get the (very)last 5 items but those 5 will be in the offset. 🙁
So on the second last page you would need to hide the ‘next page’ pagination….
Let me know if it works for you too.