Support » Fixing WordPress » in_category conditional statement

  • 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 🙂

Viewing 2 replies - 1 through 2 (of 2 total)
  • Please run the loop then set/run conditionals….the above is improper…

    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 🙂

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘in_category conditional statement’ is closed to new replies.