A weblog by Tom Coates concerning future media, social software and the web of data
Quote of the month: "This is not a brothel, there are no prostitutes here"
You can explore the archives, read the disclaimer or subscribe to an RSS feed

Hacks: "On this day" links in Movable Type

Posted June 24, 2003 12:09 PM.

Each day webloggers across the world post news, comments and little fragments of personal information onto their sites. And everything that they post will be forever associated with that specific day in history. But they're not the only sites to connect a piece of writing or a picture with a day. In fact all over the internet there are hundreds of '[something] of the day' or 'on this day' sites - from "Astronomical Picture of the Day" through to "Dilbert Cartoon of the Day". There's a whole category on Yahoo dedicated to these things.

This hack allows you to put an automated link on the bottom of each of your posts to the Dilbert cartoon (or astronomical picture, word of the day etc.) that was published on that day. You can use it to add a little context to the events on your site or just to show off your interests.

First things first - what are we trying to link to? These sites often have simple URLs that are based upon the date on which they were initially displayed. For example the "Astronomy Picture of the Day" for February 23rd 2003 has the URL:

antwrp.gsfc.nasa.gov/apod/ap030209.html

...where the six numbers near the end are the year (03), the month (02) and the day (09). The Dilbert cartoon for the same day has this URL:

dilbert.com/comics/dilbert/archive/dilbert-20030209.html

...which uses almost exactly the same format except with a the year spelled out in full (2003).

So in order to insert these links on a day-by-day basis, we're going to have to put the basic URL in place without the date elements, find some way of inserting those date elements and make sure that they're formatted so they'll work as a link. We're going to do this by using some of Moveable Type's most useful and versatile features - the <$MTEntryDate$> tag. If you insert this tag into your templates by itself it will use its default setting - which is designed for reading and will look a bit like this: "September 9, 2003 11:44 PM". But you can easily override this by using the format attribute and one or more date-tag variables. Here are a couple of examples of how you might format <$MTEntryDate$> and what the result would look like on your published page:

<$MTEntryDate format="%d %b %y"$> 
	would look like "09 Sep 03"

<$MTEntryDate format="%Y: %B, %e"$> 
	would look like "2003: September, 9"

Here are what some of those letters mean:

Month:

  %b - name abbreviated to three characters
     eg. Sep

  %B - name in full 
     eg. September

  %m - presented as two digits padded with a 0 if necessary
     eg. 09		

Day:

  %d - two digits padded with a 0 if necessary
     eg. 09

  %e - two digits padded with a space if necessary
     eg. 9

Year:

  %y - two digits padded with a 0 if necessary 
     eg. 01

  %Y - four digits. 
     eg. 2001

So to make those daily URLs all we have to do is change the original URLs to include the <$MTEntryDate$> tag like so:

From:	

  http://antwrp.gsfc.nasa.gov/apod/ap030209.html

     to:	

  http://antwrp.gsfc.nasa.gov/apod/ap<$MTEntryDate 
     format="%y%m%d"$>.html

From:

  http://www.dilbert.com/comics/dilbert/archive/dilbert-
     20030209.html

     to:

  http://www.dilbert.com/comics/dilbert/archive/dilbert-
     <$MTEntryDate format="%Y%m%d"$>.html

So this is what you'd put into your template:

<a href="http://antwrp.gsfc.nasa.gov/apod/ap
   <$MTEntryDate format="%y%m%d"$>.html">
   Astronomical Picture of the Day</a>

This hack was originally supposed to appear in the ill-fated O'Reilly "Blogging Hacks" book. I'll be putting all my contributions online over the next few days / weeks.

Comments

Please stay on-topic, informative and polite. I reserve the right to remove comments for whatever vague capricious reasons seem reasonable at the time.

You know, not to burst your bubble but at the movabletype.org website, there is already a fine Support Forum in existence with exeptional support from users who have used MT a lot longer than a few days. Why would anyone want to come to your site for MT tips? I certainly wouldn't. I certainly don't visit plasticbag.org for MT questions. I hate to say it but you're just wasting your time.

Also, what did you do with the preview button?

Posted by: Shapiro Morris at June 24, 2003 1:23 PM

I wrote some stuff for an O'Reilly book and the book's not getting published now so I'm sticking it on my site. That's all. Rather than do it all in one block, I'm sticking it up over a few days. I've also got other work to do at the moment, so this is quite nicely keeping my site ticking over while I get on with that. I also think that it doesn't do any harm to add a bit of information back into the general community. If someone finds it interesting or wants to do something similar or it inspires them to do something, then that's all to the good. With regard to some of your other comments, I've used MT for a lot longer than a few days, thank you very much, if you don't find them interesting then that's fine too (don't read 'em), but when you say I'm wasting my time I have to protest and I suggest you read this piece by Mark Pilgrim which I think sums up my feelings on this matter pretty well...

Posted by: Tom Coates at June 24, 2003 1:38 PM

Also - re the preview button - I took it off because I've been having problems with the set up of my server and haven't had time to fix them yet.

Posted by: Tom Coates at June 24, 2003 1:39 PM

Hi Tom,

i don't even use MT but i'd like to express my simpathy for you and Mark and anyone who has to read the crap assholes like this 'Shapiro' or Mark's 'Saul' leave behind. Both of you have been much more polite than i'd have been in similar circunstances.

Keep on with your superb blogging and blog about what the heck you fancy. We with half a brain will be delighted. Shapiros of this world will... bah, who cares about them anyways? :)

Posted by: mort at June 24, 2003 2:53 PM

A slight addendum: I think you have to be careful with sites like Dilbert, because the picture disappears after thirty days. And we don't want more broken picture links on this interweb...

Oh, and I'm really enjoying all the Blogging Hacks stuff on various sites. It's inspirational, and it's nice to have such a toolbox available for when I do get around to making a proper spangly weblog.

Posted by: Chris at June 24, 2003 11:10 PM

Tom Coates: It's not that I don't "like" your site, but when you are posting very specific MT related information, and I can see that it's all wrong, I would say something. I was being polite by not pointing out the obvious errors in your code. I was being nice, for heaven's sakes! There is a reason for the existence of the movabletype.org support forums. That's where you should be posting "hacks" like this so as to permit more knowledgeable users the opportunity to point out your errors. What you think is providing service to similar users like yourself is in actuality a gross disservice because giving out faulty information just confuses users and creates stress in their lives. I'm not trying to tell you what to write. I'm just asking you to be more considerate and not present yourself as an authority on Movable Type issues when you just switched from Blogger to MT a few days ago.

Mort, you are an idiot of the highest order. Just because I post a comment critical of the information that Mr. Coates is posting doesn't make me an asshole. Anytime you post something on the Internet or on the public domain, you open yourself to all sorts of praises, critical acclaim, bashing, etc. If you can't understand that simple concept, you need to quit using the computer altogether, discontinue using your online service and quit posting comments or anything on the Net. You can also learn some manners and STFU about things you don't know.

Posted by: Shapiro Morris at June 25, 2003 9:02 AM

Shapiro: "Mort, you are an idiot of the highest order. "

I have to agree with you in that point

Shapiro: "Anytime you post something on the Internet or on the public domain, you open yourself to all sorts of praises, critical acclaim, bashing, etc."

Cool. That applies to *my* bashing of your comment, so you should have taken it easier.Anyways, you can comment, i can comment on your comment and Tom can ignore us both and hopefully will.

Posted by: mort at June 25, 2003 2:24 PM

Just wanted to say thanks for the great hack. I feel bad that the book didn't get released since I was ready to go and pick it up. Anyhow, thanks for sharing the information :)

Posted by: wuji at June 29, 2003 6:12 PM

I, for one, as a newbie blogger intrigued by all the hacking potential found this above post far more illuminating, and hell, easier to figure out than the posts on MT support.

Of course, I haven't tried implementing it yet!

Posted by: Andrew at July 2, 2003 1:06 PM

I have found two interesting sources and would like to give the benefit of my experience to you.
I am tuning my pc by the best software for free, with the file search engine Fileshunt.com and Filesfinds.com May be you have your own experience and could give some useful sites too. Because this two social sites help me much.

Posted by: tatianahunt download at May 11, 2008 6:32 PM

Want to add your opinion?

© 1999-2007 Tom Coates