WebsiteBaker Support (2.8.x) > Templates, Menus & Design

automatically change the templates css on a specified date

(1/1)

snark:
I want to automatically change the css code for a website on for instance x mas, new years day, easter, etc

I found this but I would really like it if I can specify a day of the month, I presume it is quite simple but I am way to dumb ...


--- Code: ---    <link rel="stylesheet" type="text/css" href="default.css" id="siteCSS"/>
    <script type="text/javascript">

        // Get current month
        var currDate=new Date();
        var currMonth = currDate.getDate();

        // Month returned by getDate() is 0 to 11 so add 1
        currMonth = parseInt(currMonth) + 1;

        // Based on month assign style sheet name
        var newCSS = "default.css";
        if (currMonth >= 1) newCSS = "winter.css"; // Month is January or greater
        if (currMonth >= 3) newCSS = 'spring.css'; // Month is March or greater
        if (currMonth >= 6) newCSS = 'summer.css'; // Month is June or greater
        if (currMonth >= 9) newCSS = 'fall.css';   // Month is September or greater
        if (currMonth = 12) newCSS = 'winter.css'; // Month is December

        // Assign new style sheet name as the new href for "siteCSS" LINK tag
        document.getElementById('siteCSS').href = newCSS;

    </script>
--- End code ---

mr-fan:
hi snark....don't use JS if you can use PHP  :wink:

i would it try like this:


--- Code: ---<?php //colour your life
if ((date(&#39;m&#39;) == 12) || ((date(&#39;m&#39;) == 1) && (date(&#39;d&#39;) < 7))) {
echo &#39;<link rel="stylesheet" type="text/css" href="winter.css" id="siteCSS"/>&#39;;
}else{
eche &#39; <link rel="stylesheet" type="text/css" href="default.css" id="siteCSS"/>&#39;;
}

--- End code ---

or make it with a switch call for all four seasons...

dont' tested...

regards martin

snark:
ahhh thank you very much nr fan

this was exactly the anwser I was hoping for, for everyone that needs more options...


--- Code: ---<?php
if ((date(&#39;m&#39;) == 12) && (date(&#39;d&#39;) > 4) || ((date(&#39;m&#39;) == 12) && (date(&#39;d&#39;) < 6))) {
echo &#39;sinterklaas&#39;;

}else if ((date(&#39;m&#39;) == 12) && (date(&#39;d&#39;) > 25 || ((date(&#39;m&#39;) == 1) && (date(&#39;d&#39;) < 28))) {
echo &#39;kerst&#39;;


}else{
echo &#39;geen sinterklaas, geen kerst&#39;;
}

?>
--- End code ---

Navigation

[0] Message Index

Go to full version