Grow your CSS skills. Land your dream job.

[Solved] Changing Body Background

  • # June 1, 2010 at 5:48 pm

    Ok so I’ve got this bit of code in my header.php file:

    Code:
    >
    }

    Now on my home page, WP adds a class called "home" to my body tag, which i style like so:

    Code:
    .home {
    background: url(images/morning.jpg) repeat-x #fff;

    What I’d now like to do is show two different body backgrounds at different times in the day. So between the hours of 6am and 5pm I’d like the body background to be (morning.jpg) and between 6pm and 5am I’d like to to display a different body background image (night.jpg).

    How would I go about doing something like this?

    Thanks in advance!

    # June 3, 2010 at 6:30 pm

    You could do something like this:

    Code:
    < ?php

    $time = date("H");

    if ($time >= 9 && $time < 18) { ?>

    < ? }

    else { ?>

    < ? }; ?>
    # June 4, 2010 at 8:05 am
    "TheDoc" wrote:
    You could do something like this:

    Code:
    < ?php

    $time = date("H");

    if ($time >= 9 && $time < 18) { ?>

    < ? }

    else { ?>

    < ? }; ?>

    Where would I place that in my code?

    # June 4, 2010 at 12:16 pm

    That would be in your <head> section.

    # June 4, 2010 at 7:38 pm

    No luck. I’m not having any background image show at all. Any ideas?

    # June 5, 2010 at 7:39 pm

    Solved! Cheers TheDoc, and thanks for your patience.

    # June 7, 2010 at 2:43 am

    No worries – glad you got it sorted!

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".