Automatic Date-Based Template Edits

Have you ever wanted to

  • use a different stylesheet on a specific date (a holiday, perhaps)
  • show/hide part of your template on a certain date?

One example is RSS Awareness Day. I’d suggested that on May 1st, in observance of RSS Awareness Day, some bloggers should edit their stylesheets to make their blog orange for the day. I’ll use it as an example.

Basically, you want to check what day it is, see if it is equal to May 1st, and if it is, display a second stylesheet. So you add your line of code under your existing stylesheet like this:

<link rel="stylesheet" href="url_to_style.css" type="text/css" media="screen" />
<?php if (date('md') == '0501') { ?><link rel="stylesheet" href="url_to_rss_awareness.css" type="text/css" media="screen" /><?php } ?>

As you can see, the first line is the normal stylesheet, and the second line is just another style with a little bit of PHP trickery surrounding it. The bold letters 0501 mean “May 1st.” If you wanted April 1st, you’d change them to 0401, or 0603 for June 3rd.

Since stylesheets cascade, as their name suggests, you don’t need a whole new stylesheet for the RSS Awareness styling. You can just redefine the appropriate portions in your new file. Just add rules for links, colors for certain elements, etc.

  • Siddharth

    This would be sure helpful to customise the blog look on special festivals and occasions. Like we have seen the Google adwords have shown an option to change the ad placements to custom theme on Halloween last year and Yahoo! do that on every special days.