Title: If statement error
Last modified: August 20, 2016

---

# If statement error

 *  Resolved [M J](https://wordpress.org/support/users/m2j/)
 * (@m2j)
 * [13 years, 7 months ago](https://wordpress.org/support/topic/if-statement-error/)
 * Hello all,
 * I’m trying make a theme that has different background images for varying pages
   of a website. I’ve attempted to use if statements to do this using the code below:
 *     ```
       <?php /*
       Template Name: People
       */?>
   
       <?php get_header(); ?>
   
       <?php if ( is_page('page1')){ ?>
       <img src="<?php bloginfo('stylesheet_directory'); ?>/images/backgrounds/image1.jpg" class="bg" align="middle" />
       <?php if ( is_page('page2')){ ?>
       <img src="<?php bloginfo('stylesheet_directory'); ?>/images/backgrounds/image2.jpg" class="bg" align="middle" />
       <?php if ( is_page('page3')){ ?>
       <img src="<?php bloginfo('stylesheet_directory'); ?>/images/backgrounds/image3.jpg" class="bg" align="middle" />
       <?php } else { ?>
       <img src="<?php bloginfo('stylesheet_directory'); ?>/images/backgrounds/default.jpg" class="bg" align="middle" />
       <?php } ?>
   
       <div id="blogcontent" class="content-white researchers">
   
       <div id="submenu">
       <?php if ( !function_exists('dynamic_sidebar')
               || !dynamic_sidebar('people') ) : ?>
       <?php endif; ?>
       </div>
   
       <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
   
       <div id="scroll">
   
       <div id="content">
       <h2><?php the_title(); ?></h2>
   
       <?php the_content(); ?>
       </div>
   
       </div>
   
       <?php endwhile; else: ?>
   
       <p>Sorry, no posts matched your criteria.</p>
   
       <?php endif; ?>
   
       <div align="center"><?php posts_nav_link(); ?></div>
   
       </div>
   
       </body>
       </html>
       ```
   
 * However, when I try to use this – I get an error referencing the last line of
   the code above:
 * `Parse error: syntax error, unexpected $end in /home/user123/user123.com/dev/
   wp/wp-content/themes/wpthemefolder/page-template1.php on line 56`
 * Can anyone tell me how I can fix this? Am I missing something?
 * Thank you in advance.
    MJ

Viewing 1 replies (of 1 total)

 *  Thread Starter [M J](https://wordpress.org/support/users/m2j/)
 * (@m2j)
 * [13 years, 7 months ago](https://wordpress.org/support/topic/if-statement-error/#post-3133854)
 * bah… nevermind – figured it out… I forgot to close the if statements lol
 * sorry – it has been a long day…
 * fixed code:
 *     ```
       <?php if ( is_page('page1')){ ?>
       <img src="<?php bloginfo('stylesheet_directory'); ?>/images/backgrounds/image1.jpg" class="bg" align="middle" />
       <?php } ?>
       <?php if ( is_page('page2')){ ?>
       <img src="<?php bloginfo('stylesheet_directory'); ?>/images/backgrounds/image2.jpg" class="bg" align="middle" />
       <?php } ?>
       <?php if ( is_page('page3')){ ?>
       <img src="<?php bloginfo('stylesheet_directory'); ?>/images/backgrounds/image3.jpg" class="bg" align="middle" />
       <?php } else { ?>
       <img src="<?php bloginfo('stylesheet_directory'); ?>/images/backgrounds/default.jpg" class="bg" align="middle" />
       <?php } ?>
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘If statement error’ is closed to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 1 participant
 * Last reply from: [M J](https://wordpress.org/support/users/m2j/)
 * Last activity: [13 years, 7 months ago](https://wordpress.org/support/topic/if-statement-error/#post-3133854)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
