WP_Query, three iterations of theLoop
-
I’ve been hunting and trying for a couple days now.
In one unresolved forum thread, Otto42 was close to solving my problem, but the user fell off. Otto42 had asked the user to explain intentions. here’s my attempt
I have 3 categories: feature(cat=14), style(cat=10) , and music(cat=11)
A post has to be in either music or style or both, or all three,
but a post cannot be in just feature.(currently, i have 9 posts, 4 music, 4 style, and 1 in feature and style)
on my home.php
I want to show 1 post from the category= feature(cat=14)
Then show 3 most recent posts from the category style(cat=10)
then 3 from the category music(cat=11)
without duplicating a single post.(i’ve got the CSS stuff under control)
The code below is the closest I got.
I wasn’t able to maintain the $do_not_duplicate variable across all three loops.
I tried the super loop, the triple loop, etc..(i’m running the site, on MAMP so i can’t send link:
<?php get_header(); ?> <!-- MODULE 02 --> <div id="maincontent"> <div id="rightwindow"> <?php get_sidebar(); ?> </div><!-- div id right window--> <div id="leftwindow"> <div id="thefeature"> <h2> This is the start page </h2> <?php $temp_query = clone $wp_query; ?> <!-- Do stuff... --> <?php $my_query = new WP_Query('cat=14&showposts=1'); while ($my_query->have_posts()) : $my_query->the_post(); ?> <!-- Do special_cat stuff... --> <?php the_title(); ?> <?php the_excerpt(); ?> <?php endwhile; ?> // now back to our regularly scheduled programming <?php $wp_query = clone $temp_query; ?> </div> <!-- div id thefeature --> <br class="clearfloat" /> <div id="sectionwrap"> <div id="section2"> <h2> STYLE STYLE SECTION 02</h2> <?php $temp_query2 = clone $wp_query; ?> <?php $my_query2 = new WP_Query('showposts=3&cat=10&cat=-14'); while ($my_query2->have_posts()) : $my_query2->the_post(); update_post_caches($posts); ?> <!-- Do special_cat stuff... --> <?php the_title(); ?> <?php the_excerpt(); ?> <?php endwhile; ?> // now back to our regularly scheduled programming <?php $wp_query = clone $temp_query2; ?> </div> <!-- div id section2 --> <div id="section1"> <!-- Do other stuff... --> <h2> MUSIC MUSIC SECTION 01 </h2> <?php $temp_query3 = clone $wp_query; ?> <?php $my_query3 = new WP_Query('showposts=3&cat=-10&cat=11&cat=-14'); while ($my_query3->have_posts()) : $my_query3->the_post(); update_post_caches($posts); ?> <!-- Do special_cat stuff... --> <?php the_title(); ?> <?php the_excerpt(); ?> <?php endwhile; ?> // now back to our regularly scheduled programming <?php $wp_query = clone $temp_query3; ?> </div> <!-- div id section1 --> </div> <!-- div id sectionwrap --> </div> <!-- div id leftwindow--> </div> <!-- div id maincontent--> <br class="clearfloat" /> <div id="footer"> <h4> THis is the footer crap </h4> <!-- >$your_query = new WP_Query('showposts=1&cat=3&paged='. $paged); --> <?php get_footer() ?>
thanks in advance
- The topic ‘WP_Query, three iterations of theLoop’ is closed to new replies.