richarduk
Member
Posted 10 months ago #
Latest version WP (2.7)
Problem - two loops, the second loop mustn't show any of the posts from the first loop.
I've read the codex http://codex.wordpress.org/The_Loop and to be honest when it deals with this problem it's either just plain wrong or it's muddled. It repeats itself impossibly
To fix the problem replace
<?php if (have_posts()) : while (have_posts()) :
the_post(); if( $post->ID == $do_not_duplicate ) continue;
update_post_caches($posts); ?>
Then replace
<?php if (have_posts()) : while (have_posts()) :
the_post(); if( $post->ID == $do_not_duplicate ) continue;
update_post_caches($posts); ?>
EDIT: Think I've got it working
richarduk
Member
Posted 10 months ago #
Okay, here's how it should be - the codex was definitely muddled. I've made it look a bit simpler for noobs like me.
FIRST LOOP
<?php $my_query = new WP_Query('cat=3&showposts=12');
if (have_posts()) : while ($my_query->have_posts()) : $my_query->the_post();
$do_not_duplicate[] = $post->ID;?>
<!-- Do stuff... -->
<?php endwhile; ?>
<?php else : ?>
<h2>You forgot to create any posts !</h2>
<?php endif; ?>
SECOND LOOP
<?php query_posts('order=DESC&showposts=100&cat=3'); ?>
<?php if (have_posts()) : while (have_posts()) : the_post();
if($post->ID == $do_not_duplicate[0] ||
$post->ID == $do_not_duplicate[1] ||
$post->ID == $do_not_duplicate[2] ||
$post->ID == $do_not_duplicate[3] ||
$post->ID == $do_not_duplicate[4] ||
$post->ID == $do_not_duplicate[5] ||
$post->ID == $do_not_duplicate[6] ||
$post->ID == $do_not_duplicate[7] ||
$post->ID == $do_not_duplicate[8] ||
$post->ID == $do_not_duplicate[9] ||
$post->ID == $do_not_duplicate[10] ||
$post->ID == $do_not_duplicate[11] ||
$post->ID == $do_not_duplicate[12] ||
$post->ID == $do_not_duplicate[13] ||
$post->ID == $do_not_duplicate[14] ||
$post->ID == $do_not_duplicate[15] ||
$post->ID == $do_not_duplicate[16]
) continue; update_post_caches($posts); ?>
<!-- Do stuff... -->
<?php endwhile; ?>
<?php else : ?>
<h2>You forgot to create any posts !</h2>
<?php endif; ?>
What I would like to know is if there's any way the second loop can be simplified when it comes to preventing posts within the $do_not_duplicate array from appearing?
I want to show a hundred posts (at least) in multiple categories (not text posts - thumbnail images, using custom fields).
Any ideas?