This is old content! The graveyard is a snapshot of content created from 2002-2005. For new stuff, visit Maniacal Rage.
 

Graphical Date Tutorial

posted on january 12, 2003, tag: movable type

I have a feeling eventually someone who uses MT will ask me how I did the dates on this site. In a preemptive response (and also because it's something I think people would use if they knew how to do it), I have compiled a simple tutorial. To do this, all you need is to be running Movable Type. Many thanks to James who pointed out how complicated I made this the first time around. The tutorial has been updated and is significantly easier...

An image for each day (01-31), an image for each month (Jan-Dec)First, you need to create an image for each day (01-31, 1-31, whatever you like) and an image for each month (Jan-Dec, 01-12, 1-12, again, whatever). You can also include the year if you like (I didn't, but will explain how to add it). Name your images so that the days are named 01.gif, 02.gif, etcetera from 01 to 31 and the months are named the same, 01.gif through 12.gif. Once you have all the images done, which is a pain, I know, you can upload them to your server in two different folders. For this tutorial, I am going to assume you use images/numbers and images/months. Move onto the coding step.

The next step has to take place inside your <MTEntries> tag. Inside this block, you would normally get the date by doing something like this:

<MTDateHeader>
     <$MTEntryDate format="%x"$>
</MTDateHeader>

The nice thing is, however, that MT includes support for each part of the date to be pulled out separately. This is what we're gonna do. Replace the block above with this:

<MTDateHeader>
<img src="/images/numbers/<$MTEntryDate format="%d"$>.gif" alt="<$MTEntryDate format="%d"$> / <$MTEntryDate format="%B"$>" title="<$MTEntryDate format="%d"$> / <$MTEntryDate format="%B"$>" border="0" /><br />
<img src="/images/months/<$MTEntryDate format="%m"$>.gif" alt="<$MTEntryDate format="%d"$> / <$MTEntryDate format="%B"$>" title="<$MTEntryDate format="%d"$> / <$MTEntryDate format="%B"$>" border="0" />
</MTDateHeader>

Simple. So now you have two images that are stacked together and create the date. Note that I've added in alt and title tags that will give you something like 12 / January when moused over. You can remove those if you wish. Use this however you see fit.

A little further...

If you wish to do what I did (stick the date in the upper left corner so that text wraps around it), you're going to have to use some CSS. I picked this technique up from css/edge. He calls it Boxpunch. It's very simple, and works perfectly in the latest versions of IE and Mozilla as well as Safari, Opera and even Netscape 4 (!). IE 5.1 Mac doesn't seem to like it as much. Oh well.

You're gonna need two styles. Place the following in your CSS file:

.grab {
     margin-top: 0px;
     padding: 0 0 0 0;
}
.punch {
     float: left;
     position: relative;
     text-align: left;
     width: 42px;
     height: 45px;
     padding: 0 0 0 0;
     border: 0px;
}

The .grab style is used to encapsulate the entire entry. And the .punch style is used to put the date graphics in the upper left corner. Text will wrap around it correctly. So then, building on what we had before (the two image references) we can instead do this—after your date code, before your <$MTEntryBody$> tag:

<div class="grab">
<MTDateHeader>
<div class="punch">
<img src="/images/numbers/<$MTEntryDate format="%d"$>.gif" alt="<$MTEntryDate format="%d"$> / <$MTEntryDate format="%B"$>" title="<$MTEntryDate format="%d"$> / <$MTEntryDate format="%B"$>" border="0" /><br />
<img src="/images/months/<$MTEntryDate format="%m"$>.gif" alt="<$MTEntryDate format="%d"$> / <$MTEntryDate format="%B"$>" title="<$MTEntryDate format="%d"$> / <$MTEntryDate format="%B"$>" border="0" />


</MTDateHeader>
// The rest of your MT code here

After placing all of your other MT code into that comment area, your date graphics will be in their place and you'll be all set.

I hope this answers any questions you have. Please feel free to ask more if you need help.

Comments

There are 16 comments, comments are closed

Linus on 01/13/2003:

Those graphical dates are the best thing ever. Why not just use classes instead of IDs though?

Garrett on 01/13/2003:

Generally speaking (correctly me if I'm wrong here, people), IDs are for structure... boxes, etc. Classes are more for items inside the structure. That's at least how I always do it.

Linus on 01/14/2003:

I always thought the difference was purely semantic... I use IDs for major page elements, and classes for anything smaller that repeats itself, although either works for either purpose. I've noticed that Netscape 4 ignores IDs... I've never noticed any difference in how they actually work, though.

Where did you get this idea? Maybe I've been wrong.

James on 01/14/2003:

This seems to me like a massively overcomplicated way of achieving this!

I used to do graphical dates too - http://www.infinitemonkeys.co.uk/gasgiant/old - slightly ripped off Derek Powazek's log - http://www.powazek.com/zoom/log - and I simply did it by creating a load of GIFs for all the numbers from 1 to 31 (01.gif, 02.gif etc.) and twelve GIFs for the months (again 01.gif, 02.gif etc.) and bunged them in separate 'month' and 'day' sub-folders of my images folder. Then all you need to do is place two <img> tags in your MT template that uses the MTDateEntry tag to point to the right files. By naming them numerically, you don't need to anything clever at all. Or am I missing something?

Garrett on 01/14/2003:

Sometimes it takes someone telling you you're a fucking idiot before you realize you're a fucking idiot. You are that person for me today, James. It's a classic "Garrett move"—completely over thinking something. I will fix this tutorial tonight when I get home from work.

Linus on 01/14/2003:

Don't worry; over-thinking is one of my trademarks too. :)

Garrett on 01/14/2003:

I've updated this... much simpler now. Also running the simpler version on Rage. Thanks for the heads up, James!

Faf on 01/14/2003:

i'd love to see it done with 24 images.

10 for 0-9 numers
12 for months
1 for "-" or "/" as a date seperator
1 for ":" for time seperator.

I'm thinking along the lines of "get" the day or month or year or hour or min or second ... discard any leading zeros, split into an array and use that to insert the images.

This looks long winded but it'll allow for adding of "year" images w/o creating an image tag for every year.

I'll see if i can make it work though, but i'm sure someone will beat me to it.

Faf on 01/14/2003:

correction: "... without creating an image [del]tag[/del]..."

Garrett on 01/14/2003:

It's a lot simpler to do a year graphic than that. Just create four or five years. I really doubt you're gonna still be using the same design in 2005. And I really doubt you have blog archives from more than four years ago. So that leaves you only having to make about 9 images. That's not too bad.

As far as time goes, I think this is taking a simple idea of the edge. Do you really need that much?

Faf on 01/15/2003:

yeah :)

Linus on 01/15/2003:

But then why not just use text? :)

John Barker on 01/16/2003:

Inspiring!

Ciam on 01/18/2003:

This creates a really polished look. I love it.

However, my first thought when looking at the finished result, was, "Why use graphics. That's SO 1995..." ;-)

It seems like the use of graphics in this case goes against everything that CSS stands for. Use those simple CSS classes/IDs/whatever, and use type instead of graphics. Eliminate the tedium of creating all the graphics from type, and speed up the rendering ever so slighly as well...

Yes, this does introduce issues with cross-browser/cross-platform rendering, but it doesn't seem like those issues would be TOO difficult to solve...

Am I missing some issue (certainly possible)? I'll try to implement on my site. If I get it working, I'll repost here.

Oh, and since I haven't really said it yet, this trick kicks ass!

/c

Garrett on 01/18/2003:

It also introduces issues related to ugly type faces. I mean, CSS is fantastic and all, but every now and then, isn't it nice to use it in conjunction with something you can't create using plain-text?

If I had used just text for those dates, they would have had to be Georgia or Verdana, or something else entirely "body-copy," and I just didn't want that. I wanted something that would add to the look of the site, and not look like it was just part of the content.

Garrett on 02/13/2003:

I've updated this tutorial to use DIV classes instead of DIV ids. This way your code will validate in XHTML.


See Also

View the archive

Original iPod Introduction
How far we've come in just a few short years. Here's where it all started.

Front Row on Non-iMacs
Going to try this tonight!

WriAShorStorWe!
DY starts a one-week short story writing event for people to lazy to enty NaNoWriMo. VerCooIdea.

Lost Rhapsody
Funny Flash movie using Weird Al music and Lost stuff. Lyrics make a surprising amount of sense!

Jed's Other Poem
Unsolicited music video made on an Apple ][. Fantastic!

Printers Output Secret Barcode
The government is keeping tabs on what you print, with the help of major printer companies.

Dreamhost Promo Codes
DH already has very cheap, very good hosting—this just sweetens the deal.

Photos of the new iPod
Just received my new iPod and I put a few photos up.

PEZ MP3 Player
Funny idea that actually looks kind of neat. I like that it comes pre-loaded with "indie" music.

HD Easter Egg
"My Name is Earl" on NBC gives viewers with HD TVs a little easter egg. Cute, but weird.