xoops forums

faucess

Just popping in
Posted on: 2010/8/15 12:31
faucess
faucess (Show more)
Just popping in
Posts: 2
Since: 2010/4/26
#1

How to change css depending on the time??

Hello,

First, apologize for my English hehe.

I'm trying to change the css of a theme depending on time of day. I entered the following code on theme.html but I get errors.
Someone could help me?

<link rel="stylesheet" type="text/css" media="all" href="
<?php  $hour date('H');  
if ((
$hour >= 6) and ($hour <= 19))  
{
echo 
"<{$xoops_imageurl}>css/blue.css"
}  
else  
{     
echo 
"<{$xoops_imageurl}>css/red.css"
?> 
" />


I tried to do work in several ways, but I can not.

Thank you very much for your time.

playsome

Not too shy to talk
Posted on: 2010/8/15 13:44
playsome
playsome (Show more)
Not too shy to talk
Posts: 197
Since: 2009/4/15
#2

Re: How to change css depending on the time??

Hello,

Interesting idea, change the theme depending on time of day.

Although I do not know how you would do this in PHP I have found a javascript which may do it.

<SCRIPT LANGUAGE="JavaScript">
<!-- 
Begin
function getCSS()
{
datetoday = new Date();
timenow=datetoday.getTime();
datetoday.setTime(timenow);
thehour datetoday.getHours();

if (
thehour 20)
display "tree_twilight.css";
else if (
thehour 17)
display "tree_sunset.css";
else if (
thehour 14)
display "tree_afternoon.css";
else if (
thehour 11)
display "tree_noon.css";
else if (
thehour 7)
display "tree_morning.css";
else if (
thehour 4)
display "tree_sunrise.css";
else if (
thehour 1)
display "tree_twilight.css";
else
display "tree_sunset.css";

var 
css '<';  css+='link rel="stylesheet" href=' display ' /';  css+='>';

document.write(css);
// End -->
}
</
script>
<
script language="javascript">getCSS();</script>


The code is from this website http://www.katgal.com/2007/03/time-se ... -css-switcher-change.html.

I hope you get it working.

faucess

Just popping in
Posted on: 2010/8/15 14:04
faucess
faucess (Show more)
Just popping in
Posts: 2
Since: 2010/4/26
#3

Re: How to change css depending on the time??

Great!

It works perfectly, thank you very much! You took the headache of several days hehe.

Greetings!