Multiple loops, 2 Categories, All Posts
-
Im having trouble with “multiple loops”. I read the codex on “the loop”, along with some others. Im really new to this, ive never built a website before, and im learning fairly quickly.
In essence, what i’m trying to do is the following:
Category X: List one post
Category Y: List one post
List all other posts, minus the two posts.
The idea behind this, is to list Category X and Y side by side, at the top of my page, then continue and have all my others posts (from all categories) listed below them. (the styling is complete, the PHP coding is what im having trouble with.
This is what ive got so far for category X (featured)
<?php $my_query = new WP_Query(‘category_name=featured&showposts=1’);
while($my_query->have_posts()) :
$my_query->the_post();
$do_not_duplicate = $post->ID; ?>and this is for Category X (news)
<?php $my_query = new WP_Query(‘category_name=news&showposts=1’);
while($my_query->have_posts()) :
$my_query->the_post();
$do_not_duplicate = $post->ID; ?>Then i used this to post all my posts except for the other two, except it removes the post from category Y (news), and doesn’t remove the one from category X (featured)
<?php query_posts(array(‘post__not_in’=>array($do_not_duplicate)));
if (have_posts()) : while (have_posts()) : the_post();?>I added the “array” in case i wanted to show more than one post and have both removed (as far as i understood from the one of the codex pages, nevertheless it works).
Ive spent the past 4-5 hrs digging and trying different types of things to get it to work. I just want those two posts removed from all my other posts, from all categories (including category X and Y)
Thanks in advance guys.
- The topic ‘Multiple loops, 2 Categories, All Posts’ is closed to new replies.