• I’m trying to create a page called “Franchise” and have that page call in a different header image. But it doesn’t work. This is what my code looks like in the header.php file;

    <?php if (is_home() || is_page('home')) { ?>
    <? elseif (is_page('franchise')) { ?>
    <div id="franchisebanner">
    <img src="/images/graphics/franchisebanner.jpg" />
    </div>

    What am I doing wrong?

Viewing 8 replies - 1 through 8 (of 8 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    Well, when you post code here, you should use the backtick character to mark the code. That way we can actually read it.

    Look below the posting area to see an example of “backticks”.

    Thread Starter dreamo

    (@dreamo)

    sorry about that. i inserted the backtick.

    Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    Ah. Okay then. In that case, your code doesn’t actually make any sense.

    Take this bit:

    <?php if (is_home() || is_page('home')) { ?>
    <? elseif (is_page('franchise')) { ?>

    What is that supposed to do? The elseif statement doesn’t reference anything, because the if statement hasn’t ended, and it’s not even in a proper <?php … ?> block.

    Is this the actual code you’re trying to run? Or did something go wrong in your copy+paste?

    Thread Starter dreamo

    (@dreamo)

    Hmmm..for the sake of ease, can you show me how the php code should look like?

    because this is the latest of what I have;

    <?php if ( is_page(franchise)) {
    echo '<div id="franchisebanner"><img src="/images/graphics/franchisebanner.jpg" /></div>';
    } ?>

    Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    I can’t tell you how it should look. It’s executable code. How it looks depends on the other code around it and what you want it to do.

    Post the relevant section and all the stuff around it, describe what you want it to do instead, and maybe I can help you then. But code is a creative work, it’s not simply putting together a jigsaw puzzle. I could tell you one thing, and it won’t work because it doesn’t fit with the pieces around it.

    Thread Starter dreamo

    (@dreamo)

    That makes sense. Here is what I have in the header.php file for that area;

    <div id="container"><!-- start container -->
    <div id="header"> <!-- start header -->
    <div id="ffheader">
    <img src="/images/graphics/ffheader1.gif" />
    </div>
    </div>
    <?php if (is_home() || is_page('home')) { ?>
    <div id="banner">
    <div id="flash">
    <object>flash file banner goes here. i'm just leaving it out to ease code bloating on the WordPress forum. </object>
    </div>
    </div>
    <?php if ( is_page(franchise)) {
    echo '<div id="franchisebanner"><img src="/images/graphics/franchisebanner.jpg" /></div>';
    } ?>
    <? } ?>

    Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    With that code, you’ll never see your franchise banner. Look at this snippet:

    <?php if (is_home() || is_page('home')) { ?>
    ...
    <?php if ( is_page(franchise)) {
    echo '<div id="franchisebanner"><img src="/images/graphics/franchisebanner.jpg" /></div>';
    } ?>
    <? } ?>

    No page satisfies both the first set of conditions and the second set at the same time.

    I suspect you want to do this instead:
    <?php if (is_home() || is_page('home')) { ?>
    <div id="banner">
    ...
    </div>
    <?php } elseif ( is_page('franchise')) { ?>
    <div id="franchisebanner">
    <img src="/images/graphics/franchisebanner.jpg" />
    </div>
    <?php } ?>

    Thread Starter dreamo

    (@dreamo)

    that finally did the trick. Thank you for taking the time to help me through this. I knew I was missing a couple bits of code but wasn’t sure where. thanks again.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘ifelse statement to call a different header’ is closed to new replies.