• Resolved Robert

    (@rino)


    Hi —
    Just upgraded to 2.0 all is smooth except one little thing.

    In 1.x versions I was organizing my front page like this:

    —–
    Sticky Message
    —–

    Main set of posts

    —–
    Linkspam posts (short entries mostly, er, links)
    —–

    This was achieved with this code:
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    <?php if ( in_category('21') ) { ?>
    <?php the_content(); ?>
    <?php } ?>
    <?php endwhile; ?>

    <?php rewind_posts(); ?>
    <?php while (have_posts()) : the_post(); ?>
    <?php if ( !(in_category('17')) && is_home() ) { ?>

    the posting code chunk

    <h3>LinkSpam</h3>
    <?php rewind_posts(); ?>
    <?php while (have_posts()) : the_post(); ?>
    <?php if ( in_category('17') ) { ?>
    <div class="linky" style="background:pink;border-bottom:2px solid purple;"><?php the_content(); ?></div>
    <?php } ?>
    <?php endwhile; ?>

    The first and last sections of this are working fine, pulling out only the category defined. The middle is not excluding the category defined.

    Any thoughts? TIA

    <ignore my template and organization… it’s transition time for a lot of things. :)>

Viewing 5 replies - 1 through 5 (of 5 total)
  • Did you make sure to close your if statement? That was what was tripping me up with a similar problem.

    Thread Starter Robert

    (@rino)

    Yah I did, and found another peculiar situation. If I run query posts nothing changes. If I run this line <?php while (have_posts()) : the_post(); ?>
    <?php if ( !(in_category('17')) && is_home() ) { ?>
    nothing changes but I can create a section below restricting to one category successfully, it’s the main body that still comingles the attempted excluded cat.

    Now. If I run this: <?php query_posts("cat=-17"); ?> that category DOES get excluded from the main body of entries ONLY if the post is tagged with cat id#17 only — but if for instance the post is tagged with three categories, 3, 5, && 17 then it still gets listed.

    Not sure why this is so queer. Thanks in advance. I’ll be away for a day or so but happy to answer questions if anyone has them.

    Thread Starter Robert

    (@rino)

    I took out the is_home() check and it works suddenly. Weird, I must have had something out of place.

    rino, you have a contradictory situation here. If you want ( and obviously succeed ) to exclude a category from the main post listing, but keep the others – then you should not let any posts from the excluded category be shared by non excluded categories. Seems like logic, don’t you think?

    Thread Starter Robert

    (@rino)

    petit: I don’t know if your question is sincere or if you are trolling. Here is my answer:

    Nope. The logic is strict.
    A simple example with more natural language:

    if post-categories contain category==17
    then do not show post
    else
    show post

    Nothing here is contradictory. It actually depends on what you want to do doesn’t it?

    It could be this:
    if post-categories contain category==17 && category==1
    then show post normally
    else
    show post with pink background

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