WordPress.org

Ready to get started?Download WordPress

Forums

in_category conditional statement (3 posts)

  1. K1t
    Member
    Posted 5 months ago #

    Hello, I'm trying to show different sidebars on my single template depending on what category the post is in. I'm using a conditional statement and am wondering if this is achievable as I can't get it working...

    <?php if ( in_category( '18' )) {
    include (TEMPLATEPATH . '/specialist-expertise-sidebar.php'); }
    elseif ( in_category( '4' )) {
    include (TEMPLATEPATH . '/industry-expertise-sidebar.php'); }
    else {
    if (in_category('4') && in_category('18')) {
    include (TEMPLATEPATH . '/combined-expertise-sidebar.php'); }
    }
    ?>

    So to explain:
    If the post is in category 18 then show specialist sidebar.
    Or if the post is in category 4 then show the industry sidebar.
    Or else if the post is in BOTH category 18 and 4 show the combined sidebar.

    The else statement is where I'm struggling to target both of the categories...it just goes blank instead and none of it works.

    Also I'm using in_category but unsure of the correct use here, whether I should be using is_category instead?

    Can anyone advise and help to get this working? Thank you :)

  2. Pioneer Valley Web Design
    Member
    Posted 5 months ago #

    Please run the loop then set/run conditionals....the above is improper...

  3. K1t
    Member
    Posted 5 months ago #

    So it has to go within the loop? I get a very broken layout when I try that. I am using multiple loops and all is fine until I include the code above into one of them ;) Think I've messed something up somewhere. Thanks for the tip :)

Reply

You must log in to post.

About this Topic