Easy Date-Based Image Mastheads

Around Christmas, I had a client ask for masthead imagery that would automatically swap in/out based on the time of year. Here is the HTML/PHP I used:

<img src="masthead.png" id="masthead"
class="month-<?php echo date('m'); ?>" alt="masthead" />

And here is the CSS:

#masthead {
width:300px;
height:100px;
}

.month-12, .month-01, .month-02 {
background:url(/images/winter.jpg);
}

.month-03, .month-04, .month-05 {
background:url(/images/spring.jpg);
}

.month-06, .month-07, .month-08 {
background:url(/images/summer.jpg);
}

.month-09, .month-10, .month-11 {
background:url(/images/autumn.jpg);
}

There are a number of ways to format the date info, but numerical seemed the only way to avoid any language barriers.

13 Responses {+}

Trackbacks

  1. del.icio.us links fra 29. januar, 2008 » superevil.org
  2. Sonika’s blog » Как менять картинки в шапке в зависимости от времени года
  3. Меняем Шапку Блога Автоматом | Запах денег