study the bit after ‘Note for Multiple Posts in the First Category’ in here http://codex.ww.wp.xz.cn/The_Loop#Multiple_Loops_in_Action
(about using an array to collect more than one post id to be excluded)
Alternatively you can pass the entire $do_not_duplicate array to $wp_query and only entries that match your criteria will be returned:
<?php query_posts(array('post__not_in'=>$do_not_duplicate));
if (have_posts()) : while (have_posts()) : the_post();
?>
principle:
first loop:
-collect the do-not-dup ids in array;
second loop:
-use array to exclude the ids from the loop;
-collect more do-not-dup ids in the same array;
third loop:
-use array to exclude the ids from the loop;
-collect more do-not-dup ids in the same array;
fourth/last loop:
-use array to exclude the ids from the loop;
Thanks for your response. You have to excuse my ignorance, but I’m just learning PHP yet.
So if i use this for the second loop,
<?php query_posts(array('post__not_in'=>$do_not_duplicate));
if (have_posts()) : while (have_posts()) : the_post();
?>
How do I also restrict by category and number of posts?
docu for query_posts():
http://codex.ww.wp.xz.cn/Function_Reference/query_posts
one possibility:
<?php
$args = array(
'post__not_in' => $do_not_duplicate,
'posts_per_page' => 5,
'cat' => 5
)
query_posts($args);
if (have_posts()) : while (have_posts()) : the_post();
?>
Yeah no luck, but I do appreciate the effort.
I am amazed that I cannot find a single working example of code with 3 or 4 loops with each loop having a unique query (by category and number of posts) while passing do_not_duplicate values along each loop. I’ve scoured the forums and the web and I can’t find one example that doesn’t break.
If anyone has a working example they can share I would greatly appreciate it.
Thanks again, everyone!
you could paste the code of your template into a http://wordpress.pastebin.com/ and post the link to it here – someone might be able to check if and what is wrong.
you couyld try to use wp_reset_query() between loops.
what is not working?
wrong posts?
still showing duplicates?
I finally got this to work with the help of a friend of mine. Here is the final product. Feedback, of course, is appreciated:
http://wordpress.pastebin.com/GEffXe5r