WordPress Multiple Loops Confusion -
i have multiple loops want display on wordpress blog. categories follows:
- top-story (1 per page)
- small-story (1 per page)
- normal (1 per page)
- quickfill (2 per page)
i've got 4 loops display these. i'm trying display amount of posts per page , once they've been displayed, don't show them again on page, don't want show duplicates.
my loops follows. seem getting duplicates , when i'm trying them remove duplicates tend remove without knowing how.
top story - 1st loop
<?php global $do_not_duplicate; $do_not_duplicate = array(); $paged = max(1, get_query_var('paged')); $my_query = new wp_query('category_name=top-story&posts_per_page=1&paged='.$paged); while ($my_query->have_posts()) : $my_query->the_post(); $do_not_duplicate[] = $post->id; ?> // content <?php endwhile; ?>
small-story - 2nd loop
<?php $my_query = new wp_query('category_name=small-story&posts_per_page=1&paged='.$paged); while ($my_query->have_posts()) : $my_query->the_post(); if (in_array($post->id, $do_not_duplicate)) continue; $do_not_duplicate[] = $post->id; ?> // content <?php endwhile; ?>
normal posts (note: category called normal) - 3rd loop
<?php $my_query = new wp_query('category_name=normal&posts_per_page=1&paged='.$paged); while ($my_query->have_posts()) : $my_query->the_post(); if (in_array($post->id, $do_not_duplicate)) continue; $do_not_duplicate[] = $post->id; ?> // content <?php endwhile; ?>
quickfill - 4th loop
<?php $int = 0; $my_query = new wp_query('category_name=quickfill&posts_per_page=2&paged='.$paged); while ($my_query->have_posts()) : $my_query->the_post(); if (in_array($post->id, $do_not_duplicate)) continue; $do_not_duplicate[] = $post->id; if ($int==0) { ?> <hr class="seperator" /> <div class="gr_bg_post"> <img src="<?php bloginfo('template_directory'); ?>/images/quickfill.png" /> <?php } ?> <div class="fl"> <h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4> <?php the_content('<button type="button" class="read_more_green">read more</button>'); ?> </div> <?php if ($int==1) { ?> </div> <?php } ?> <?php $int++; ?> <?php endwhile; ?>
last loop - standard wordpress protocol display posts... (i think may have duplicates)
<?php $my_query = new wp_query(array('post_not_in' => $do_not_duplicate)); if (have_posts()) : while ($my_query>have_posts()) : $my_query>the_post(); ?> // content <?php endwhile; endif; ?>
i've been trying figure out few days , can't seem stop duplicates showing, or correct posts show. greatly appreciated!
you missing query variable $my_query
in last query
$my_query = new wp_query(array('post_not_in' => $do_not_duplicate)); if ($my_query->have_posts()) : while ($my_query>have_posts()) : $my_query>the_post(); // content endwhile; endif;
Comments
Post a Comment