Displaying posts from certain categories
-
I’m trying to display post from two categories on my home page, and to style the categories differently. They are subcategories of “menu-items,” “seasonal-special” and “regular-dish.”
Seems like a pretty common task. Here’s the only code I can figure out that even comes close to working:
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <!-- "seasonal specials" is category 4, so I exclude all the others. This is tedius, and every time I add a category I have to add it here --> <?php if (in_category('1')||in_category('3')||in_category('5') ||in_category('6')||in_category('7')||in_category('8') ||in_category('9')) continue; ?> <div class="post"> content goes here </div> <?php endwhile; ?> <!-- This grabs the newest 4 menu items --> <?php query_posts('category_name=regular-dishes&showposts=4'); while (have_posts()) : the_post(); $do_not_duplicate = $post->ID; ?> <div class="menu-item-right"> content goes here </div> <?php endwhile; else: ?> <p>Sorry, no posts matched your criteria.</p> <?php endif; ?>
This works erratically. For example, currently no articles from cat 4 (seasonal specials) are showing up. Before I added cat 9 (which is a subcategory of menu items, just like cat 4) the cat 4 content was showing up correctly.
There has to be a better way to do this…
Viewing 7 replies - 1 through 7 (of 7 total)
Viewing 7 replies - 1 through 7 (of 7 total)
- The topic ‘Displaying posts from certain categories’ is closed to new replies.