in_category conditional statement (3 posts)

  1. K1t
    Posted 1 year 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 Web Design
    Posted 1 year ago #

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

  3. K1t
    Posted 1 year 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 :)

Topic Closed

This topic has been closed to new replies.

About this Topic