< ?php include '/Volumes/web/html/alan/inc/better_mt.php'?> What’s in a file name? Well it is the URL that you will publish, so make the most of it. You can make room for flexibility in your blogs if you set things so all content created is published as *.php rather than *.html.

What is PHP? A long forgotten acronym, but it is a powerful server side language for mixing in some script like commands that can make web pages be much more dynamic than static HTML. Even if you never use one iota of PHP code, your blog site can still spit out web friendly content, HTML only if you change things as described below. It is an once of prevention (well maybe more than an ounce) that creates opportunity down the road.

So in this bit of MT, we will show you how to change everything so your blog is on the PHP bandwagon, and then show you an easy way to save your individual blog posts with more meaningful urls than http://www.mycoolsite.org/blog/archives/000035.html
Of course, your web server much support PHP. Make a quick test. Open a plain text editor, and create a file with this code in it:

and save it as a file named something clever like info.php. Pop it up to your web server, and load the URL that points to the file. If your server supports PHP, you will see a long list of details about its settings (mostly unreadable geek talk). If you see just what looks like the code before… bad news, no PHP in your house.

So you have PHP. Now what? Let’s enter the world of your MT control panel. Click the TEMPLATESG button on the left side. You want to change the file names of your Main Index Template from index.html to index.php:

It is just a matter of clicking the name of the template, and editing the setting in “Output File”.

Now if this is a brand new blog, you are in fine shape, If you have been publishing to all *.html files, you will now want to rebuild the entire site to generate the files as *.php named ones. I made this switch about a year into my blogging, so my old archives have them saved under both names. Disk space is not that expensive, so it does not hurt to leave the old *.html files and not kill those thousands of people who bookmarked that old post about the pizza delivery guy and the freaky cat ;-)

The one hitch you may want to fix is any old links to the main index.html of your blog…. here is how you can easily set up a redirect in plain old HTML. Just edit the content of any old index.html at the root level of your blog to:

Next on the agenda, we want to amke sure that the monthly (daily), category, and individual archives create files that end in .php.

Click the WEBLOG CONFIG button on the left side. Then follow the link for Preferences. A little bit more than half way down is the section for ARCHiVING. I recommend the default archive being Individual (which does not prevent you from creating other types, but it means the “permalinks” generated from your front page posts will link to one URL that displays the single posting).

Below that, change the File extension for archive from html to php:

setting archive

Now is where we do some cool things. By default when you publish a post in MT, it creates a URL that is merely a file with a numerical name that is actually the identifier for where the info is in the database. Again, at a glance, this URl tells us nothing about the topic or content of a blog entry:

http://www.mycoolsite.org/blog/archives/000035.html

but with some easy MT magic, we can havbe MT publish the same content as something more meaningful:

http://www.mycoolsite.org/blog/archives/<span style="color:#c33"><strong>2004/12/15</strong></span>/won_the_lottery.php

where the marked part of the url lets us know when it was published (year/month/day) and the file name is a bit more descriptive of the content.

The simplest approach is to generate the file name based on the title of the post. You find some bloggers that do that, but end of with mile long URLs for their prolific titles, e.g.

http://www.mycoolsite.org/blog/archives/i_won_the_lottery_and _now_i_am_going_to_france_to_get_a_big_load_of_chanpagne.php

With some MT template magic, you can tell MT to publish things with the year/day/date file structure, and a file name based on say the first 15 characters of the title of the post. MT is smart enough to convert spaces to “_” and avoid other file crunching characters.

Again, click the WEBLOG CONFIG button on the left side. Then follow the link for Archives. In the field for Individual Archives (first line), enter the following in the box under Archive File Template:

This uses MT template tags to generate file names for individual entry archives, the part in red creates a file directory structure, and the part in blue creates a legal file names based on the first 15 characters of your entries title.

And then of course, you will again need to rebuild the entire blog. At this point, your entire site is now capable of supporting sophisticated PHP functionality (we will get to some later).

I should add that i use this last approach on CDB, but with an extra twist I learned from Mark Pilgrim’s Cruft-free URLs in Movable Type where the file names of individual entries are based upon the text I enter as a “keyword” while editing. This involved adding the MTIfEmpty plug-in. You can learn more about this where I described it as “Reorganizing the Dog/Blog House”.

So with some configuration work, you set the stage to go way beyond old static HTML driven blogs…

The post "Better MT-ing 1: Naming Files To Your Advantage" was originally dropped like a smoking hot potato at CogDogBlog (http://cogdogblog.com/2004/12/better-mt-3/) on December 15, 2004.

Comments are closed.