WordPress.org

Ready to get started?Download WordPress

Forums

conditional tags? (5 posts)

  1. Woopi
    Member
    Posted 3 years ago #

    hi,

    I am trying to use the conditional tags. Basically I want to say that if it is the page About choose this image with a $bannerimg. So, where do I insert that $bannerimg in my code?

    <?php if ( is_page('about')) {
    $bannerimg = about.jpg';
    } else {
    $bannerimg = 'home.jpg';}
    ?>

    ???????? <img src="$bannerimg" align="right" /> ???????

  2. alchymyth
    Forum Moderator
    Posted 3 years ago #

    use a php echo function to output the $bannerimg:

    http://php.net/manual/en/function.echo.php

  3. Woopi
    Member
    Posted 3 years ago #

    ok, but Im a real newby and how do I do that so the $bannerimg will be the src of the image?

  4. alchymyth
    Forum Moderator
    Posted 3 years ago #

    where is the image folder?

    the full code depennds on the image location;
    to start, try:

    <?php if ( is_page('about')) {
    $bannerimg = 'about.jpg';
    } else {
    $bannerimg = 'home.jpg';}
    ?>
    
    <img src="<?php echo $bannerimg; ?>" align="right" />

    as this is likely not to work, try for the last line:

    <img src="http://full_path_to_image_folder/<?php echo $bannerimg; ?>" align="right" />

  5. Woopi
    Member
    Posted 3 years ago #

    <?php if ( is_page('about')) {
    $bannerimg = 'about.jpg';
    } else {
    $bannerimg = 'home.jpg';}
    ?>

    <img src="<?php echo $bannerimg; ?>" align="right" />

    that code worked perfectly!!!! thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic