November 27, 200817 yr Hi all, I need to build a website where the appearance/background image varies depending on the time of day (say, the user's computer clock). There'll only be a few variations: morning, afternoon, evening. Is this simple to do, and if so can anyone provide any insight to help me out? Many thanks
November 27, 200817 yr I was thinking of something related to this the other day. Not too difficult - use PHP to determine the time and then serve up the relevant code.
November 28, 200817 yr I agree, PHP is your best bet. You could do something like this... I hope this works for you. Good Luck <?php $day = date("G"); switch($day) { case $day >= 8 && $day <= 9: include'styleSheet1.css'; break; case $day >= 10 && $day <= 12: include'styleSheet2.css'; break; } ?>
December 10, 200817 yr Here's what I'd do for a simple design difference between times (like the background image that you mention). Have a PHP function like this to return a word representing the hour of the day: function getHourClass() { $hour = date('G'); switch(true) { case ($hour<12): return 'morning'; case ($hour>11 && $hour<18): return 'afternoon'; case ($hour>17): return 'evening'; } } Then in your markup, have an include to insert this word as a class on your body tag like this: <body class="<?= getHourClass(); ?>"> Which means you can then refer to the differences in your CSS file like this: body.morning { /* morning css here */ } body.afternoon { /* afternoon css here */ } body.evening { /* evening css here */ }
Create an account or sign in to comment