Jump to content

Change styles based on month?


dropfaith

Recommended Posts

i Know the code below works to change style sheets based on the hour of the day but is there a possible solution to also make it change styles based on the month dynamically..

i want the site to change styles 4 times a year following the seasons  and all i have found so far is by the hour

<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>




<noscript>
<link rel="stylesheet" href="tree_sunset.css" type="text/css">
</noscript>

Link to comment
https://forums.phpfreaks.com/topic/126171-change-styles-based-on-month/
Share on other sites

You don't need javascript to do that.

in the head:

<?php
$seasoncss="";
switch(date("n")){
    case 3:
        $seasoncss="spring.css";
        break;
    case 6:
        $seasoncss="summer.css";
        break;
    case 9:
        $seasoncss="fall.css";
        break;
    case 12:
        $seasoncss="winter.css";
        break;
}
echo "<link rel=\"stylesheet\" href=\"$seasoncss\" type=\"text/css\">";

should be close and will work with javascript turned off.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.