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 usingis_category
instead?Can anyone advise and help to get this working? Thank you ??
- The topic ‘in_category conditional statement’ is closed to new replies.