Support » Fixing WordPress » Show posts except from few subcategories

  • I am showing latest 5 posts in category.php but want to hide (or do not want to show ) posts from few subcategories under particular category.

    Example : If I am in category C that has sub-categories c1, c2, c3, c4 and c5. I want to display latest 5 posts except posts in subcategory cat-3

    I hv tried it but the problem is that the loop runs 5 times and counts the skipped posts as well, though they are not displayed. So if there are 4 latest posts from c3, the category page shows just 1 latest post , since it skips the subcategory c3’s 4 latest posts.

    here the code I am using

    <?php if (have_posts()) : ?>
    			 <? if (is_category('8') or is_category('2')) { ?>
    				 <?php while (have_posts()) : the_post(); ?>
    				<? if ((! in_category('14')) and (! in_category('10')) and (! in_category('16'))) {?>
    				 <div id="category">
    				  <!-- <h2 id="post-<?php the_ID(); ?>"> -->
    				  <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php single_cat_title('');?> <?php the_title(); ?>">
    					<?php the_title(); ?></a></h2>
    					<?php the_excerpt(); ?> <?php the_time('F jS, Y') ?> <a href="<?php the_permalink() ?>" rel="bookmark">[ ... Read more ...]</a>
    					<!-- by <?php the_author() ?> -->
    				<? } ?>
    				<?php endwhile; ?>

Viewing 4 replies - 1 through 4 (of 4 total)
  • Any help ?

    I’m having the same problem, and just increasing the number of posts shown doesn’t work for several reasons. Is there any code that tells the loop not to count the hidden category posts? I can’t add any more plugins, I’m interested in code only.


    Whoops, I guess I should mentione I’m using version 2.2.2.

    Aha, found it after a little more searching (only took me a week!) Turns out I needed to exclude the category BEFORE the Loop in index.php:

    if (is_home()) {

    Worked like a charm!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Show posts except from few subcategories’ is closed to new replies.