Querying posts from one category and exclude another
-
Hi all
I’ve been setting up a portfolio theme and I’ve set it up so that the user can categorise projects in both the ‘featured’ and the ‘portfolio’ categories. The problem I’m having is that in the sidebar I want to display the 3 latest portfolio posts, but exclude the featured projects (as these are already listed above it). The following code works fine for me, with the exception that if a ‘featured’ project is one of the three most recent ‘portfolio’ projects then it only lists 2 posts instead of the desired 3. here’s the code…
<?php query_posts('showposts=3&category_name=portfolio'); $ids = array(); while (have_posts()) : the_post(); if (in_category('9')) continue; $ids[] = get_the_ID(); $portfolio_thumb_image_url = get_post_meta($post->ID, "portfolio_thumb_image_url", true); ?> <li><a href="<?php the_permalink() ?>" rel="bookmark"><img src="<?php echo $portfolio_thumb_image_url ?>" /><span><?php the_title(); ?></span></a></li> <?php endwhile; ?>
So does anyone know a work-around? Perhaps is there a way to subtract from the loop count or something? Any help would be great!
Thanks!
- The topic ‘Querying posts from one category and exclude another’ is closed to new replies.