Multiple Loop help please
-
Hello, basically I’m having a problem running multiple loops.
1st loop I have displays the latest 5 posts (ONLY) for one category, the 2nd loop displays posts for all other categories and is paginated (10 posts per page).
Seems simple enough, and is kind of working with “$do_not_duplicate”, however as this is called after query_posts, it won’t always display 10 posts (if there’s 1 or more in the 1st loop).
If however I remove the “$do_not_duplicate” function, the 2nd loop works fine, except it won’t paginate, so no-matter what page, I get the latest 10 posts.
Here’s what I have:
One query with “$do_not_duplicate”<?php get_header(); ?> <div id="container"> <div id="Quick-box"> <h2>Quick News</h2> <ul id="Quick"> <?php $my_query = new WP_Query('posts_per_page=5&cat=67'); while($my_query -> have_posts()) { $my_query -> the_post(); $do_not_duplicate[] = $post->ID; ?> <li><a href="<?php the_permalink(); ?>" title="Click To Comment"><?php the_title(); ?></a> <ul><li><?php the_content(); echo '</li></ul></li>'; } ?> </ul> </div> <?php while(have_posts()) : the_post(); if(in_array($post->ID, $do_not_duplicate)) continue; ?> <div class="post"> <h2><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2> <div class="entry"> <?php the_excerpt();?> </div> <div class="post-meta"><Strong>Posted:</Strong> <?php the_date('d F Y') ?> <strong>by</strong> <?php the_author_posts_link(); ?> | <strong>Comments:</strong> <?php comments_popup_link('0', '1', '%'); ?> </div> </div> <?php endwhile; ?> <div class="navigation"> <div class="navigation-newer"> <?php previous_posts_link('< Newer News');?> </div> <div class="navigation-older"> <?php next_posts_link('Older News >'); ?> </div> </div> </div> <?php get_sidebar();?> <?php get_footer();?>…and 2 “query_posts()” (1 “cat = 67″, 1 cat != 67”)
<?php get_header(); ?> <div id="container"> <div id="Quick-box"> <h2>Quick News</h2> <ul id="Quick"> <?php query_posts('posts_per_page=5&cat=67'); while(have_posts()) { the_post();?> <li><a href="<?php the_permalink(); ?>" title="Click To Comment"><?php the_title(); ?></a> <ul><li><?php the_content(); echo '</li></ul></li>'; } ?> </ul> </div> <?php query_posts('posts_per_page=10&cat=-67'); while(have_posts()) : the_post(); ?> <div class="post"> <h2><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2> <div class="entry"> <?php the_excerpt();?> </div> <div class="post-meta"><Strong>Posted:</Strong> <?php the_date('d F Y') ?> <strong>by</strong> <?php the_author_posts_link(); ?> | <strong>Comments:</strong> <?php comments_popup_link('0', '1', '%'); ?> </div> </div> <?php endwhile; ?> <div class="navigation"> <div class="navigation-newer"> <?php previous_posts_link('< Newer News');?> </div> <div class="navigation-older"> <?php next_posts_link('Older News >'); ?> </div> </div> </div> <?php get_sidebar();?> <?php get_footer();?>Incase I haven’t made it clear, I want 10 posts per page displayed in the 2nd loop.
Thanks in advance,
Jason
The topic ‘Multiple Loop help please’ is closed to new replies.