• I’m trying to make a condition that creates sidebar content if a specific category archive is being viewed OR if a post in that category is being viewed.

    I was thinking this would work but it’s not:

    <?php
    $post = $wp_query->post;
    if ( in_category(19) || is_category(19) ) : ?>

    DO SOME STUFF

    <?php endif; ?>

    Any suggestions?

    Thanks,
    Sean

Viewing 7 replies - 1 through 7 (of 7 total)
  • Hello

    <?php if (is_category('19') || in_category('19')) { ?>
    DO SOME STUFF
    <?php } ?>

    That should work! 🙂

    Thread Starter somlor

    (@somlor)

    That worked! Thanks. 🙂

    I want no just one category that not show? how to do that? that I mean, I have 15 and 19 category, and I don’t want this category show up in front my page.

    How to do that?

    <?php if ( !(in_category(’29’)) ) { ?>

    <?php } ?>

    Should exclude category 29.

    paulweber

    (@paulweber)

    Interesting.
    Is there anything like an “AND” condition?

    I.e. if variable 1 AND variable 2 are true, then display content X
    else if variable 3 AND variable 4 are true, then display content Y?

    Thank you – it would be precious help!

    Paul Weber

    aaronsportfolio

    (@aaronsportfolio)

    Paul, here is a solution:

    <?php
    
    if (is_category('xyz')) {
            Do something;
            }
    elseif (category('xyz2')) {
            Do something else ;
            }
    elseif (category('xyz3')) {
            Do something else;
    		}
    else {
            Do something if none of the above are true;
            }
    ?>

    – is_category can be replaced with any other conditional tag, ex: is_single(‘some single post’) OR is_post(‘some post’)

    Paul another option is

    <?php
    if ($1 == TRUE && $2 == TRUE) {

    echo “something”;

    } elseif ($3 == TRUE && $4 == TRUE) {

    echo “something else”;

    } else {

    echo “something completely different”;

    }

    ?>

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘is_category OR in_category condition’ is closed to new replies.