Forums

[resolved] Using Conditional Statement To Control Header image (4 posts)

  1. WMS Group
    Member
    Posted 2 years ago #

    I am currently using the code below to control the header image if a certain page is navigated to, in this case "About the Author" which is page 2.

    <div id="header">
    <img src="<?php bloginfo('template_url');
    if(is_page('2')) {
    echo '/images/header-about.jpg'; }
    else { echo '/images/header.jpg'; } ?>" width="899" height="283" />
    </div>

    How would I add multiple statements, ie,

    if(is_page('3')) {
    echo '/images/header-links.jpg'; }
    else { echo '/images/header.jpg'; } ?>" width="899" height="283" />
  2. Mark / t31os
    Moderator
    Posted 2 years ago #

    Basic if/else example below..

    Example:

    if( is_page'3' ) {
    // STUFF
    }
    elseif( is_page('4') ) {
    // OTHER STUFF
    }
    elseif( is_page('5') ) {
    // MORE STUFF
    }
    else {
    // DEFAULT STUFF
    }

    Alternatively you could use a switch statement, but the if/else is likely easier in this case.

  3. WMS Group
    Member
    Posted 2 years ago #

    Thank you so much! Works like a charm ;)

  4. Mark / t31os
    Moderator
    Posted 2 years ago #

    You're welcome.. :)

Topic Closed

This topic has been closed to new replies.

About this Topic