Blog Updates Part 1 | March 26, 2004

Since setting up this site, there have been a number of things about it that have bugged me. I kept adding them to my todo list, but never quite got round to doing them. By themselves, they were all quite small things. but together, they amounted to quite a lot of work. They were also things that could potentially mess up the site, so for a while I thought, "if it aint broke, don't fix it". However, last week I finally decided to bite the bullet and fix some of these annoyances.

The first annoyance was the way my templates were structured in MT. When I set this site up I was very much an MT newbie, so built it on the back of the default templates. Since then, I've pretty much overhauled the individual templates, but the structure was pretty much the same.

One of the things that annoyed me was the amount of duplication. When I build a PHP site, I'm used to having header and footer files as well as various other includes like nav bars, side bars etc. However, in this site, everything was duplicated. This meant, if I wanted to change the name of a file say, I'd have to change the link in the nav bar of every page.

So first off, I created a new template module called "Nav" which looked something like this.

<div id="nav"><a href="<MTBlogRelativeURL>index.php"><img src="<MTBlogRelativeURL>images/home.gif" alt="Home" width="26" height="19" border="0" title="Home" /></a> ...

And then called this module from every template page.

Next I created a generic Header and Footer template module. I realised the header would be a problem, as it obviously contained some meta data like the title of each page. Using Brad Choate's MTIfEmpty I tried to do something like this:

<title><$MTBlogName$><MTIfNotEmpty var="ArchiveTitle">: <MTArchiveTitle></MTIfNotEmpty></title>

Thinking that if the page was an archive page, the title would get displayed, but it if wasn't, you'd just get shown the blog name. Unfortunately when I tried to rebuild the index page, I'd get an error message saying that <MTArchiveTitle> was being used in a place that it shouldn't be used. There is probably some simple way of doing this, but in the end I gave up and created two Header template modules. One for the archive pages and one for all the other pages.

Next thing to do was to create a generic side bar. Before, I only had a side bar on my home page. However I wanted to have a side bar on every page. Again I created a new template module and called it in from every template page. This worked fine on my homepage and archive index pages, but the links went all screwy on the monthly and category pages. My "Last 6 posts" started displaying the last six posts from that category, rather than the last 6 posts from the whole blog. Again, I'm sure there was a simple way of getting it too work in MT, but as a stop gap, I created another side bar template module, without the "Last 6 posts" to use on the sub pages. What I'll probably do is create an index template instead and then use a php include to attach it to each page. I'd have preferred to find an elegant MT only solution, but couldn't figure one out.

I've been using MTW3CValidate on my index page to validate the code when I rebuild it. If the code is valid, a W3C button gets displayed, whereas nothing gets displayed if it doesn't validate. I added the <MTW3CValidate> tags to my header and footer, but noticed that Safari was timing out on the rebuild pages. I tried adding the tags to the individual templates, but rebuilds were still timing out for the individual pages. It would work intermittently on other browsers with longer time out times, but ended up being far to patchy to be able to use.

So I ran into a few problems, and things aren't working quite as I'd like them to. However the template structure makes much more sense now that I've created header, footer, nav and sidebar template modules. This was all in preparation for my next step, updating the archiving format so that my posts had meaningful url's, and moving the whole blog up a directory. However I'll leave that till Blog Updates Part 1.

Posted at March 26, 2004 8:58 PM


Brad said on March 27, 2004 12:51 AM

When I redesigned my site in CSS and set up each page with it’s on side bar and what not. However, it was so hard to update stuff because I would have to do it for like 7 pages per “section.” Anyway, I set up templates in MT also and it’s been so much easier to update and have a more dynamic site.

Jack said on March 28, 2004 1:14 PM

I followed pretty much the same route from adapting default templates to going a bit more modular (and have been putting off making more meaningful URLs for quite a time) but found that using Template Modules in MT made rebuilds, and therefore commenting, incredibly sluggish - that may be peculiar to my installation, but creating Index Templates and including them with PHP worked much better than the MTInclude method. I don’t know enough about these things to say why this is the case, but it might be worth a try…