WordPress.org

Support

Support » How-To and Troubleshooting » conditional tags?

conditional tags?

  • 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” /> ???????

Viewing 4 replies - 1 through 4 (of 4 total)
  • Michael

    @alchymyth

    Forum Moderator

    use a php echo function to output the $bannerimg:

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

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

    Michael

    @alchymyth

    Forum Moderator

    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" />

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

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

    that code worked perfectly!!!! thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘conditional tags?’ is closed to new replies.
Skip to toolbar