Title: How do you write an elseif statement?
Last modified: August 20, 2016

---

# How do you write an elseif statement?

 *  [celticks](https://wordpress.org/support/users/celticks/)
 * (@celticks)
 * [13 years, 9 months ago](https://wordpress.org/support/topic/how-do-you-write-an-elseif-statement/)
 * Sorry this may be a very dumb question but how can I add an elseif to this:
 * <?php if (is_page(10) || $post->post_parent==”10″) { ?>
 * <p>Apples</p>
 * <?php } else { ?>
 * <p>Oranges</p>
 * <?php } ?>

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

 *  [converting2wp](https://wordpress.org/support/users/converting2wp/)
 * (@converting2wp)
 * [13 years, 9 months ago](https://wordpress.org/support/topic/how-do-you-write-an-elseif-statement/#post-2954018)
 *     ```
       ...
       <p>Apples</p>
   
       <?php } elseif (/* some condition */) { ?>
   
       <p>Pears</p>
   
       <?php } else {
       ...
       ?>
       ```
   
 * See [http://www.php.net/manual/en/control-structures.elseif.php](http://www.php.net/manual/en/control-structures.elseif.php)
 * See also [switch](http://www.php.net/manual/en/control-structures.switch.php)
 *  [michael.mariart](https://wordpress.org/support/users/michaelmariart/)
 * (@michaelmariart)
 * [13 years, 9 months ago](https://wordpress.org/support/topic/how-do-you-write-an-elseif-statement/#post-2954024)
 * Another note…
 * When you are using if() or for() or any other contorl statement in a template
   file, it can be eaiser to read and debug if you use the alternative syntax. As
   an example:
 *     ```
       <?php if ($val == 1): ?>
         <p>Apples</p>
       <?php elseif ($val == 2): ?>
         <p>Oranges</p>
       <?php else: ?>
         <p>Pears</p>
       <?php endif; ?>
       ```
   
 * It means the same thing, but can make it eaiser to read in template code.

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

The topic ‘How do you write an elseif statement?’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 3 participants
 * Last reply from: [michael.mariart](https://wordpress.org/support/users/michaelmariart/)
 * Last activity: [13 years, 9 months ago](https://wordpress.org/support/topic/how-do-you-write-an-elseif-statement/#post-2954024)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
