Forums

[resolved] excluding category from posts (6 posts)

  1. Robert
    Member
    Posted 6 years ago #

    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. :)>

  2. Berko
    Member
    Posted 6 years ago #

    Did you make sure to close your if statement? That was what was tripping me up with a similar problem.

  3. Robert
    Member
    Posted 6 years ago #

    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.

  4. Robert
    Member
    Posted 6 years ago #

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

  5. petit
    Member
    Posted 6 years ago #

    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?

  6. Robert
    Member
    Posted 6 years ago #

    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

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags