Support » Fixing WordPress » trouble excluding category

  • I have been at this for hours and hours, trying different things. Basically, there should be 3 posts on the home page: the most recent one in category A, recent in category B, and a featured one that is either catA OR catB along with the category “featured”.

    SO, I got it working by first calling a post in BOTH category A and featured. but the post is also showing up as the listing in category A. So I tried adding on to the second loop as here:

    <?php $posts = get_posts('category=A&numberposts=1&offset=0');
    foreach ($posts as $post) : start_wp(); ?>
    <?php if (in_category('featured')) continue; ?>

    but that skips the category entirely.

    I’m at a loss. I was trying some variations of showing posts in columns where it wouldn’t repeat posts, but couldn’t get two different categories to work with that. Pointers greatly appreciated!

Viewing 2 replies - 1 through 2 (of 2 total)
  • OK, so I have something fudged. Using this:

    <?php query_posts(array('category__and' => array(15,31))); ?>
      <?php while (have_posts()) : the_post(); ?>
    <h6><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h6>
    <?php the_excerpt(); ?>
    <p class="readmore"><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>">Read full <?php the_title(); ?> story</a></p>
      <?php endwhile;?>
    <?php query_posts('cat=15&showposts=1&offset=1'); ?>
    <?php $posts = get_posts('category=15&numberposts=1&offset=1');
    foreach ($posts as $post) : start_wp(); ?>
    <p class="readmore"><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></p>
    <?php endforeach; ?>
    <?php query_posts('cat=16&showposts=1'); ?>
    <?php $posts = get_posts('category=16&numberposts=1&offset=0');
    foreach ($posts as $post) : start_wp(); ?>
    <p class="readmore"><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></p>
    <?php endforeach; ?>

    But it only works if there is a single category along with featured. Categories 15 and 16 are children of category 17, is there any way to have the first post be most recent post in 17, with 1 each of 15 and 16 shown below, but no duplicates?

    oops, it posted twice

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘trouble excluding category’ is closed to new replies.