• Resolved CKeating

    (@ckeating)


    Hi,

    I’m new to WordPress and am trying to teach myself how to build themes. I don’t have a website and am working locally on my computer. I have some code which works on a standard php page and am having trouble transferring it so it works in WordPress. The code shows a different image in a div depending on what time of day it is:

    <?php
    $h = date(‘G’);

    if ($h < 12) $img = ‘images/morning.png’;
    else if ($h < 18) $img = ‘images/afternoon.png’;
    else $img = ‘images/evening.png’;
    ?>

    <div class=”picturebox”><?php echo $img ?></div>

    When I insert this code into my WordPress homepage it just displays the file path as a text string instead of the image. I know images in WordPress need to be preceded by php bloginfo (‘template directory’) but can’t seem to get that to work in this example. Could anyone help me with how to adapt this code so it works in WordPress – any help would be much appreciated!

    Many thanks,
    Claire

Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘assigning an image to a variable’ is closed to new replies.