faucess faucess
  • Just popping in
  • Just popping in
  • Joined: 2010/4/26 14:25
  • Group: Registered Users
  • Posts: 2
  • Posted on: 2010/8/15 8:31
How to change css depending on the time?? #1
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 playsome
  • Not too shy to talk
  • Not too shy to talk
  • Joined: 2009/4/15 16:38
  • Group: Registered Users
  • Posts: 197
  • Posted on: 2010/8/15 9:44
Re: How to change css depending on the time?? #2
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 faucess
  • Just popping in
  • Just popping in
  • Joined: 2010/4/26 14:25
  • Group: Registered Users
  • Posts: 2
  • Posted on: 2010/8/15 10:04
Re: How to change css depending on the time?? #3
Great!

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

Greetings!
How to effectively post a question in the Xoops forums? - Read here...
Design by: XOOPS UI/UX Team