Published Jan 15, 2006

If you check out the monthly and category archives below, you’ll notice that the formerly separate moblog, linkblog, and diary parts of this site share the same archive pages. A lot of blogs out there have just this kind of content, but store it completely seperately; if you’d like to have posts from your moblog, linkblog, and blog or diary, all on the same archive page, and are using Movable Type, you can do it by following the instructions below.


So, first thing, there are a few assumptions I’m going to make here. The first assumption is that you’re running Movable Type 3.2 — if you’re not, you need to upgrade to make this work. The second is that you have PHP available (although you could use any other language, if you know it, I’ll be providing code in PHP here). Third, I’m assuming that you’re publishing your pages statically, not dynamically (everything should work on dynamic pages, but I haven’t tested it). Fourth, I’m assuming that your host runs Apache, or some other Web server that has an .htaccess-type redirection syntax. Finally, I’ll assume that you’re comfortable editing your templates in the text editor of your choice.


Throughout this entry, we’ll refer to:

  • Master Blog, your main blog and the one that generates the home page of your site; for most people this will be a diary-like blog.
  • Secondary Blog, which will generally be a linkblog, blogroll, moblog, etc.
  • Archive Pages, which always refer to the Master Blog’s archives

The Procedure

  1. Category Name Unification
  2. Change Your Archive Path
  3. Unified Monthly Archives Using MT
  4. Unified Category Archives Using PHP
  5. One RSS Feed to Rule Them All
  6. Clean-up With .htaccess

1: Category Name Unification

The first step is to make sure that, to the extent you categorize your blog entries, you have matching categories across all of the blogs whose archives you’re planning to share. In versions of Movable Type prior to 3.2, you cannot have categories that share the same name, even in different blogs, but 3.2 removes that limitation.

If you have a 1:1 correspondence between categories in different blogs, and you’re comfortable with a tool like PHPMyAdmin or the MySQL command-line interface, you can use that tool to rename categories in the secondary blog to match the master blog. If you’re not comfortable with PHPMyAdmin, you’ll have to create a new category in your secondary blog, with the same name as the category that you’d like to match in the master blog, and move all of your entries from the old category, without the matching name, over to that new category.

If you have multiple categories in a secondary blog that you’re planning to show on the same archive page in your master blog, you’ll need to create a new category in your secondary blog that matches the name of the category you’d like to match in your master blog. You should then make all of the categories that you’d like to show on the master archive page subcategories of your new, matching-name category. Finally, you’ll need to move one of your entries to the top-level category, because MT doesn’t create archive pages for categories with no entries.

2: Change Your Archive Path

This is the crazy part, and you may not need to do it. However, if you didn’t create the folder your archives are in yourself, but, instead, had MT automatically create it for you, and your Web server is configured in specific ways, then you may not have the priveleges to upload files into your own archive folder in your own Web space.

So, step 0 is just to try to upload any arbitrary file to your archive folder to see if you have the priveleges. If you do, great. If not, you’ll need to:

  1. Create a new archive folder (with a different name than your old folder — you don’t have the priveleges to delete or reaname your old folder)
  2. Set the priveleges on that folder so that everyone can read, write, and execute in it (CHMOD 777, for you command-line geeks)
  3. Go to your control panel
  4. Click Settings
  5. Click Publishing
  6. Change your archive path to match the folder that you just created
  7. Rebuild! If there’s an error, check that you did number 2 right

Don’t worry that we just broke all of your incoming links, we’ll fix those in the final step.

3: Unified Monthly Archives Using MT

I lied, a little bit, in this headline — we’ll use a little bit of PHP as well as some MT to get unified date archives. But, in this case, MT will work for us, because all of the date archives use the same file naming by default, and MT gives us access to that file name.

To get your archive page to use any PHP code you place in your template, you’ll need to change the extension of the final, rendered page from the usual .html or .htm to .php. To do this, go to your MT control panel, click the Settings button, choose the Publishing tab, and, under Publishing Preferences, set the File Extension for Archive Files to php. When you rebuild your site, this will change all of your archive files’ extensions to .php, and all of the links generated by MT to these date archives will automatically be updated as well. While this step will break incoming links, we’ll fix those at the end of the whole process.

Now, MT uses <MTArchiveDate format=”%Y_%m”> as its file name for date archives. So, in your master date archive page, where you want the secondary blog archives to appear, just use the syntax:

.html" ?>

That will cause PHP to fetch the entire page from your secondary blog at that URL and insert the html from that page into the master archive page, in place of the line of PHP code. Now, having one complete html page inside another complete html page probably won’t turn out too well, so you need to strip down the secondary page (don’t worry, it’ll never be shown on its own).

Remember that PHP will actually include all of the contents of the template for the secondary archive page in the master archive page that is actually displayed, so you should think of the output of the template as just a component of a page, rather than as a stand-alone page. As such, you don’t need your <head> and <body> elements, or your site’s header, navbar, etc.; just have the code that lists the month’s entries in the manner which you prefer. For instance, many will blogs will need just a single <div> containing <MTEntries> in the template for the secondary archive page.

4: Unified Category Archives Using PHP

You’ll use an essentially identical process to set up the category archives, except the PHP code will change. Start out by changing the file extension setting for the master archive page, then strip down the secondary archive page.

Now, because there are fewer legal characters in a URL than there are characters you may use in a category name, MT has some set of algorithms it uses to simplify category names to create the filename for the category archive page. I don’t know what those are, but that’s ok, we can use PHP to duplicate the final output. In your master category archive template, instead of the PHP code shown above use the following:

$archive = $_SERVER['PHP_SELF'];
include "$archive";

This code gets the filename of the page, stores that filename in the variable $archive, and then gets the page with the same filename at the URL you specify (presumably the path to the place your secondary blog stores its category archive pages).

5: One RSS Feed to Rule Them All

If you’re riding the RSS bandwagon, you probably want to have just one feed for your entire blog (I’m sorry about that RSS thing, by the way, but I guess we’re stuck with it). Fortunately, there’s a quick trick to getting content from all of your blogs into one single RSS feed. First, install MultiBlog. Then, create a new blog just for your RSS feed. Prepare your RSS feed template(s) as normal, but, around the <MTEntries> tag, include the new <MTMultiBlog> tag. Using MTMultiBlog, set up this RSS blog to rebuild when either the master blog or any of the secondary blogs are rebuilt. Please read the MTMultiBlog documentation for more information, instructions, and syntax.

It’s true that nothing points to this rss-only blog, but we’ll fix that in the last step. There’s sure a lot to be done in that last step!

6: Clean Up With RSS

Finally, we’re on the last step — cleaning up after the mess we’ve left. This mess consists of:

  • When changing categories in Step 1, if any categories were renamed, incoming links to those category pages may be broken
  • If we changed the archive path in Step 2, incoming links to archive pages have been broken
  • Now that we created unified archives in Steps 3 and 4, we no longer want to have links leading to secondary blog archive pages
  • Automatic discovery of the RSS feed is broken because the feed is at an unexpected location

We’ll fix all of these problems using .htaccess. As mentioned at the beginning of this entry, this method relies on .htaccess, so if you’re on Windows you have a problem; there are .htaccess-like tools for IIS, so you could ask your host to install and run one; alternatively, you could use small ASP scripts to duplicate the below syntax and then Server.Transfer the user to the desired page. I leave that as an exercise for the reader.

If you don’t already have an .htaccess file, create a new, blank text document and put the following at the top:

Options +FollowSymlinks
RewriteEngine on

To fix any renamed category from Step 1, use the following syntax:
Redirect /archive/oldpage.html
Where oldpage is the old archive page name (generated by MT) and newpage is the new archive page name (also generated by MT — you may have to follow some links on your site to find out the right page names).

To fix the archive path changed in Step 2, use the following syntax:
RewriteRule ^archives/(.*).html(.*)$1.php$2 [r=301,nc]
Where the first path starts with an ^ then contains the path from the root to the archive folder, then a (.*) then your old file extension and then another (.*), and the URL is the URL to your new archive path, with the exact page names replaced with the $1 and $2 characters ($1 inserts whatever was matched by the first (.*) and $2 the second).

To fix the unified archives created in Steps 3 and 4, use the following syntax:
Redirect /archive/oldpage.html
Where oldpage is the old archive page name (generated by MT) and newpage is the new archive page name (also generated by MT — you may have to follow some links on your site to find out the right page names).

To make everything except Firefox autodiscover the RSS feed, use the following syntax:
Redirect /index.rdf [r=301,nc]
Where the full URL is the full URL of the RSS feed that you want people to see.

And that’s it! Now your unified site should work. Enjoy it!

1 Comment

um sure ;)

im sure thats totally useful, its moreso hot than anything, tho