Creating a blog sitemap with Movable Type

December 30th, 2008. This post was published long time ago on the Italian version of my blog then moved here after the English blog has been opened. Please note that the following post can contain outdated information and (probably) multiple typos.

This tutorial targets Movable Type 3.2.

Although the template may work on later versions, you are strongly encouraged to update it according to the specific Movable Type tag syntax provided by your current version.

Movable Type provides an excellent template engine that can be easily tweaked to create a XML Sitemap.

Basically, you just need to create a new index template and ask Movable Type to rebuild it each time your blog is updated.

The Sitemaps Protocol enables you to inform search engine crawlers about URLs on your websites that are available for crawling and helps search engines to find all your pages.

To create a new template enter the Movable Type administration panel.

Blog Dashboard > Templates > Indexes and press Create New Index Template to add a new template to your blog configuration.

Choose an easy to understand Template Name — for example Sitemaps — and an easy to remember file name — for example sitemap.xml.

Configure Movable Type to rebuild the template automatically when rebuilding index templates and fill the Template Body textarea with the following code

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.google.com/schemas/sitemap/0.84">
<url>
<loc><$MTBlogURL encode_xml="1"$></loc>
<priority>1.0</priority>
<changefreq>daily</changefreq>
</url>
<url>
<loc>**http://simonecarletti.com/blog/index.xml**</loc>
<priority>1.0</priority>
<changefreq>daily</changefreq>
</url>
<url>
<loc>**http://simonecarletti.com/blog/atom.xml**</loc>
<priority>1.0</priority>
<changefreq>daily</changefreq>
</url>
<MTEntries lastn="9999">
<url>
<loc><$MTEntryPermalink encode_xml="1"$></loc>
<lastmod><$MTEntryModifiedDate utc="1" format="%Y-%m-%dT%H:%M:%SZ"$></lastmod>
</url>
</MTEntries>
<MTIfArchiveTypeEnabled archive_type="Category">
<MTTopLevelCategories>
<MTIfNonZero tag="MTCategoryCount">
<url>
<loc><$MTCategoryArchiveLink$></loc>
</url>
</MTIfNonZero>
<MTSubCatsRecurse>
</MTTopLevelCategories>
</MTIfArchiveTypeEnabled>
<MTIfArchiveTypeEnabled archive_type="Monthly">
<MTArchiveList archive_type="Monthly">
<url>
<loc><$MTArchiveLink$></loc>
</url>
</MTArchiveList>
</MTIfArchiveTypeEnabled>
</urlset>

Please note that bold styled strings must be replaced with your own settings.

Save the new template and… your new sitemap file is ready.

Sitemaps Template

That's all! Now login into your Google Account, go to the Sitemaps admin panel and submit your sitemap to Google.

Before closing this article, let's have a look at the template source code.

First of all, according to Google Sitemap Specifications, you need to declare the XML file and schema.

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.google.com/schemas/sitemap/0.84">

Now you are ready to start your URL list.

Add your blog main URL using <$MTBlogURL encode_xml="1"$> template tag. Set the higher priority value and (if required) the update frequency.

<url>
<loc><$MTBlogURL encode_xml="1"$></loc>
<priority>1.0</priority>
<changefreq>**daily**</changefreq>
</url>

Then list the Atom and RSS feeds

<url>
<loc>**http://simonecarletti.com/blog/index.xml**</loc>
<priority>1.0</priority>
<changefreq>daily</changefreq>
</url>
<url>
<loc>**http://simonecarletti.com/blog/atom.xml**</loc>
<priority>1.0</priority>
<changefreq>daily</changefreq>
</url>

and all entries.

<MTEntries lastn="9999">
<url>
<loc><$MTEntryPermalink encode_xml="1"$></loc>
<lastmod><$MTEntryModifiedDate utc="1" format="%Y-%m-%dT%H:%M:%SZ"$></lastmod>
</url>
</MTEntries>

Finally, complete the recipe with all category indexes

<MTIfArchiveTypeEnabled archive_type="Category">
<MTTopLevelCategories>
<MTIfNonZero tag="MTCategoryCount">
<url>
<loc><$MTCategoryArchiveLink$></loc>
</url>
</MTIfNonZero>
<MTSubCatsRecurse>
</MTTopLevelCategories>
</MTIfArchiveTypeEnabled>

and monthly archives, if they are enabled.

<MTIfArchiveTypeEnabled archive_type="Monthly">
<MTArchiveList archive_type="Monthly">
<url>
<loc><$MTArchiveLink$></loc>
</url>
</MTArchiveList>
</MTIfArchiveTypeEnabled>
</urlset>

The original tutorial was posted by Nial Kennedy. The code published above is an updated version based on the original post.