Title: IF statement inside IF Statement?
Last modified: July 13, 2017

---

# IF statement inside IF Statement?

 *  Resolved [jayo](https://wordpress.org/support/users/jayo/)
 * (@jayo)
 * [8 years, 10 months ago](https://wordpress.org/support/topic/help-if-statement-inside-if-statement/)
 * Trying to perform an IF statement inside another IF statement… but unsure how
   to perform this.
 * I have an ad running after four post listings on the front page, but I’m trying
   to call different ad tags based on homepage, category or post pages.
 * Can anyone help?
 *     ```
       <?php if ($count == 3) : ?>
       <div class="content-ad">
   
       <?php if (is_home()) { ?>
       1st Ad Code
   
       <?php } elseif (is_category('Entertainment')) { ?>
       2nd Ad Code
   
       <?php } elseif (is_category('Lifestyle')) { ?>
       3rd Ad Code
   
       <?php } else { ?>
       4th Ad Code
       <?php } ?>
   
       </div>
       <?php endif; $count++; ?>
       ```
   
    -  This topic was modified 8 years, 10 months ago by [jayo](https://wordpress.org/support/users/jayo/).
    -  This topic was modified 8 years, 10 months ago by [Jan Dembowski](https://wordpress.org/support/users/jdembowski/).

Viewing 5 replies - 1 through 5 (of 5 total)

 *  [jonpeck777](https://wordpress.org/support/users/jonpeck777/)
 * (@jonpeck777)
 * [8 years, 10 months ago](https://wordpress.org/support/topic/help-if-statement-inside-if-statement/#post-9316668)
 * You probably want to make those different if statements into variables.
 * There’s a real cool thread on stack overflow on ways to do that.
 * Cheers
 * [https://stackoverflow.com/questions/6483323/if-statement-within-an-if-statement](https://stackoverflow.com/questions/6483323/if-statement-within-an-if-statement)
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [8 years, 10 months ago](https://wordpress.org/support/topic/help-if-statement-inside-if-statement/#post-9317323)
 * what is the result of your code?
 * in which file are you using it?
 *  Thread Starter [jayo](https://wordpress.org/support/users/jayo/)
 * (@jayo)
 * [8 years, 10 months ago](https://wordpress.org/support/topic/help-if-statement-inside-if-statement/#post-9317332)
 * Thanks Jon, that post gives me a headache. I usually find examples of what I 
   need and mod it. I’ll look over it and figure it out.
 * MICHAEL, it just spits our error. Doesn’t work. Im using in INDEX.php
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [8 years, 10 months ago](https://wordpress.org/support/topic/help-if-statement-inside-if-statement/#post-9317708)
 * the code in itself is error free –
 * can you post the exact text of the error message, and post the full code of the
   index.php template?
 *  Thread Starter [jayo](https://wordpress.org/support/users/jayo/)
 * (@jayo)
 * [8 years, 10 months ago](https://wordpress.org/support/topic/help-if-statement-inside-if-statement/#post-9319873)
 * Sorry guys. The code does work. I must have done something wrong the first time
   around.
 * Thanks for your help though.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘IF statement inside IF Statement?’ is closed to new replies.

## Tags

 * [php](https://wordpress.org/support/topic-tag/php/)

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 5 replies
 * 3 participants
 * Last reply from: [jayo](https://wordpress.org/support/users/jayo/)
 * Last activity: [8 years, 10 months ago](https://wordpress.org/support/topic/help-if-statement-inside-if-statement/#post-9319873)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
