• Resolved M J

    (@m2j)


    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

    (@m2j)

    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.