• Resolved ryuujinsilver

    (@ryuujinsilver)


    Okay, I am trying to make it so I can show a different image depending on what page I am on. I have tried this if statement.

    <?php
    if (is_home()) {
     echo'<img src="locationofimage" alt="" />'
    } elseif (is_page('2')) {
     echo'<img src="locationofimage" alt="" />'
    } else {
     echo'<p>Just a Test</p>'
    }
    ?>

    But when I do this nothing shows up on the page at all (completely white)

    However if I just put the image path with no PHP

    <img src="locationofimage" alt="" />

    The image shows up just fine. Any suggestions.

    BTW, yes I have done a search for similar questions, which is where I got this idea in the first place to no avail.

Viewing 3 replies - 1 through 3 (of 3 total)
  • You might want to look if your if statement is working at all. I`m unfamiliar with the 2 functions you call.

    Also, check if echo ‘<img src=”locationofimage” alt=”” />’ works. Then if it doesnt, press control+u and see what url its really trying to find the image at.

    Thread Starter ryuujinsilver

    (@ryuujinsilver)

    Thanks for the quick responce.

    That’s the thing I don’t think the if statement is working. I guess I was wondering if there was an alternative way to display a different image depending on the page id.

    Also I checked the echo, and it does work.

    Thread Starter ryuujinsilver

    (@ryuujinsilver)

    I’ve figured it out! Thanks for your help. For anyone who wants to try this is works like this.

    <?php if (is_page(2)) { ?>
    
        <img src="location of image.png" alt="" />
    
        <?php } elseif (is_page(3)){ ?>
    
        <p>Whatever you want</p>
    
        <?php } ?>
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘If statement for pages’ is closed to new replies.