Title: in_category conditional statement
Last modified: August 21, 2016

---

# in_category conditional statement

 *  [Kitty](https://wordpress.org/support/users/k1t/)
 * (@k1t)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/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)

 *  [Pioneer Web Design](https://wordpress.org/support/users/swansonphotos/)
 * (@swansonphotos)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/in_category-conditional-statement/#post-4720949)
 * Please run the loop then set/run conditionals….the above is improper…
 *  Thread Starter [Kitty](https://wordpress.org/support/users/k1t/)
 * (@k1t)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/in_category-conditional-statement/#post-4721033)
 * 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.

## Tags

 * [in category](https://wordpress.org/support/topic-tag/in-category/)
 * [in_category](https://wordpress.org/support/topic-tag/in_category/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [Kitty](https://wordpress.org/support/users/k1t/)
 * Last activity: [12 years, 2 months ago](https://wordpress.org/support/topic/in_category-conditional-statement/#post-4721033)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
