Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2008-12-19 19:50:01
- masa
- Member
- From: Asturias, Spain
- Registered: 2005-11-25
- Posts: 1,091
Timed CSS
Hi everyone,
I was asked by a client to alter the look of their site slightly for the Xmas season, which can be done basically by replacing a few key colours in the CSS.
I can create a secondary style sheet to override the colour definitions and add that to the template manually and remove it again later. But how would I go about loading it automatically based on the current time, so I won’t have to go through this again next year?
Something like…
if current time is ≥ than 15. December and ≤ than 1. January
load xmas.css
else
do nothing
Any help would be much appreciated.
Last edited by masa (2008-12-19 19:50:53)
Offline
Re: Timed CSS
Could you some how use smd_if to look at the REQUEST_TIME? I know it can look at server variables.
Piwik Dashboard, Google Analytics Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker
Offline
Re: Timed CSS
I was going to suggest something similar.
If that doesn’t work I was thinking you could set a PHP variable or a <txp:variable />
and test it with smd_if, but then figured if you have to drop into PHP anyway to get the date, you might as well save yourself a plugin and just do the entire thing directly in PHP within your <head>
:
<txp:php>
$now = time();
if (date("m",$now) == 12 && date("d",$now) >= 15) {
echo css(array("n" => "xmas.css", "format" => "link"));
}
</txp:php>
Untested, but something like that should do it.
Last edited by Bloke (2008-12-20 09:12:43)
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
#4 2008-12-20 09:51:41
- masa
- Member
- From: Asturias, Spain
- Registered: 2005-11-25
- Posts: 1,091
Re: Timed CSS
Thanks for the suggestions.
I tried Bloke’s php snippet since it looks really simple, but that gives me a
Fatal error: Call to undefined function css() in (server/path)
Any ideas? I don’t know the first thing about php.
Offline
Re: Timed CSS
masa wrote:
Fatal error: Call to undefined function css() in (server/path)
Strange, it works for me… erm… where did you put the code? I put mine in a form that was called from within my <head>
and it rendered out a link to xmas.css.
Stumped. Ummm, anyone else?
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
#6 2008-12-20 12:07:13
- masa
- Member
- From: Asturias, Spain
- Registered: 2005-11-25
- Posts: 1,091
Re: Timed CSS
Well, I tried it on a self-standing html page first instead of a Textpattern template ;-)
It’s working fine now :-)
Thanks very much as usual!
Offline
Re: Timed CSS
masa wrote:
Well, I tried it on a self-standing html page first instead of a Textpattern template ;-)
lol, ok that would explain it! Glad you got it sorted.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
#8 2008-12-20 15:52:25
- masa
- Member
- From: Asturias, Spain
- Registered: 2005-11-25
- Posts: 1,091
Re: Timed CSS
See, you can’t trust me with php ;-)
Actually I was a bit surprised that there is no native Textpattern tag for this like a <txp:if_current_time>
That would certainly help php numpties like myself.
Offline
Re: Timed CSS
Now you’ve said that, give it about half an hour and Gocom’ll probably whip up rah_today or rah_timenow or something equally cool ;-) Combined with smd_if that’d sort you out, without having to get your hands mucky in PHP.
EDIT: Actually, a function like this is going to be part of the new smd_calendar plugin so if you happen to want date-based stuff you get the ability to output the current date and time for free (and of course, if you can output it, you can check it with smd_if).
Last edited by Bloke (2008-12-20 16:40:32)
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
Re: Timed CSS
Bloke wrote:
Now you’ve said that, give it about half an hour and Gocom’ll probably whip up rah_today or rah_timenow or something equally cool ;-) Combined with smd_if that’d sort you out, without having to get your hands mucky in PHP.
I actually already have a closed Textpattern plugin solution for that :D It just uses UNIX to the if-conditional to check what time is, and also a tag that shows current time. Both are one-line plugins, because strtotime is used.
Offline
Re: Timed CSS
Bloke wrote:
Actually, a function like this is going to be part of the new smd_calendar plugin …
I love it how you casually drop a bomb like that :-)
TXP Builders – finely-crafted code, design and txp
Offline
Re: Timed CSS
jakob wrote:
I love it how you casually drop a bomb like that :-)
:-)
Well, it’s still in development courtesy of a bounty request by mrdale but it’s shaping up to be another monster and is actually taking on a life of its own :-)
I’ll release it if there’s enough interest in article-based event management on that thread (don’t wanna step on the toes of zem_event or jmc_event_manager) but the sponsors get first dibs of course.
The addition of expiry to an article has just opened up an entire new world…
Last edited by Bloke (2008-12-20 19:35:11)
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline