Title: Another if/else issue
Last modified: August 21, 2016

---

# Another if/else issue

 *  [timpan](https://wordpress.org/support/users/timpan/)
 * (@timpan)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/another-ifelse-issue/)
 * I am getting an error say there is an unexpected ‘{‘. What I’m trying to do is
   say:
 * If the page has a featured image, use it in this div background
 * else
 * is any page or post, use this array.
 * Any ideas as to what I am doing wrong?
 *     ```
       <?php if ( is_page() ) { ?>
   
       <?php global $post; ?>
       			<?php
       			$src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), array( 5600,1000 ), false, '' );
       			?>
       			<div style="background: url(<?php echo $src[0]; ?> ) !important; min-height: 100%; background-size: cover !important; background-position: center !important; margin: auto; padding: 20px 0; max-width: 1000px;">
   
       <?php } else ( is_page() || is_single() )  { ?>
   
       	<?php
       		$homeDiv = '<div id="wrapper-home">';
       		$homedueDiv = '<div id="wrapper-home2">';
       		$hometreDiv = '<div id="wrapper-home3">';
       		$allDivs = array();
   
       		array_push($allDivs, $homeDiv, $homedueDiv, $hometreDiv);
   
       		$randomNumber = rand(0, count($allDivs) - 1);
   
       		echo $allDivs[$randomNumber];
       	?>	
   
       <?php } ?>
       ```
   

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

 *  [catacaustic](https://wordpress.org/support/users/catacaustic/)
 * (@catacaustic)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/another-ifelse-issue/#post-3929800)
 * It took me a little while to see it too, but…
 * When you have an if()/else statement, the else can’t have any conditions. Because
   you’ve added a conditional check after the else it breaks because that’s not 
   allowed to be there. If you want that you need something like this:
 *     ```
       if($conditon_1) {
   
       } elseif ($conditon2) {
   
       }
       ```
   
 *  Thread Starter [timpan](https://wordpress.org/support/users/timpan/)
 * (@timpan)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/another-ifelse-issue/#post-3929808)
 * Thanks for the reply.
 * So set up the variables of condition_1, etc. and in theory this should work. 
   Makes sense. I’ll give it a try tomorrow.
 *  [catacaustic](https://wordpress.org/support/users/catacaustic/)
 * (@catacaustic)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/another-ifelse-issue/#post-3929811)
 * You can still have the same conditions that you do now, that’s no problem. You
   just need to make it `elseif()` instead of `else`.

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

The topic ‘Another if/else issue’ is closed to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 2 participants
 * Last reply from: [catacaustic](https://wordpress.org/support/users/catacaustic/)
 * Last activity: [12 years, 11 months ago](https://wordpress.org/support/topic/another-ifelse-issue/#post-3929811)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
