Creative Commons License
This weblog is licensed under a Creative Commons License.

« Yahoo! hosted Movable Type rebuild fix | Main | Sanyo Xacti VPC-HD1 »

Improved Archive Page for MovableType

Before I moved my boy's blog over to MovableType, I had built a way to view and sort all the blogs I posted in Blogger. That was a necessity, since Blogger doesn't offer any way to show all your archives or search your blog. When I moved the blog to MovableType, I just went with the default archive page - which after using it a couple of times, I hated! It is just a giant spew of every blog entry (378 in the case of my boy's blog), without any ability to make heads or tails of them. So today I set about re-creating my old archive page, only in Movable Type.

In my old method, I had to manually create an entry for each blog in a text file - a pain in the butt, to say the least. Thanks to MovableType's flexibility in creating auto-recreating index files, this problem can be made to go away. So the first step is to create an index template that will build the file with all the archive data needed for the improved archive page. I created an index template (with the output file "bloglist.txt") as follows:

<MTENTRIES lastn="99999">
<$MTEntryPermalink$>####<$MTEntryDate format="%Y-%m-%d-%H%M" $>####<$MTEntryTitle remove_html="1">####<$MTEntryAuthorUsername$>####<MTENTRYCATEGORIES><$MTCategoryLabel encode_xml="1"$>####</MTENTRYCATEGORIES>
</MTENTRIES>

This creates a file with every entry (well, assuming you have less than 99,999 entries ). It saves away the link, the published date, the author, and the categories for the entry. The #### separator is arbitrary, it could be anything that isn't likely to be found in the blog data.

Next step is to create an index template with the output file "bloglist.php" (or whatever name suits your fancy) that processes this data. The code is here: bloglist.php.txt (13 KB). Also I changed out the archives link to point to bloglist.php instead of the crappy old archive page, and deleted my "master archive" index just to spite it.

Things of note to use this code:

  1. Line 189 is where you put in the URL to the bloglist.txt file.
    GetBlogData( "http://yourblog.com/bloglist.txt" );
  2. My blogs are 3 column, and I put the Alpha & Gamma div's into template modules as I reuse them in all my templates. My alpha div is style="float: left;" and my gamma div is style="float: right;" so that they can be rendered ahead of the usually slower-to-render central beta div. Line 228 & 230 is where these get included, and will require customization:
    <$MTInclude module="Alpha"$>
    <$MTInclude module="Gamma"$>
  3. If you do two column or one column blogs, you will also need to tweak lines 232 and 233 to be be alpha divs instead of beta.

That's it. This will allow the archives to sort be sorted by date (newest to oldest and oldest to newest) & by blog title, to be filtered by author and category, and to show more granular date information. To see this in action, check out my boy's blog archive.

Sadly, my real job starts again Tuesday and my Christmas break of messing with PHP will end. Writing PHP for a hobby is like building model airplanes for a hobby, only only it's limited to the uber-geeks.