Team LiB   Previous Section   Next Section

8.3 Archiving Options

One of Movable Type's greatest strengths is the number of different archiving options it offers. When you post an entry to your blog, it generally appears both on the front page of your site (your index), as well as on any archive pages you have designated. For example, if your site has an archive of all your entries by month any new entry that you post is added to the archive for the newest month, automatically. The system takes care of all the work of creating the archive files and filling them with the correct data.

Movable Type allows you to archive your entries by day, week, and/or month, by category and by individual entry. This last option means that each entry that you post has a page dedicated to displaying only that entry in the archives. This works well for sites with long entries or article-based sites, in particular.

8.3.1 Archiving by Category

Category archives are a flexible way to manage your archives. Because categories can represent any sort of structure you wish to impose, your category archives can be used to emulate that structure on your public web site. This allows Movable Type to act as more than just a blogging tool; for example, it can be used to manage:

  • A news site, where categories might be standard newspaper sections (Local News, Politics, Entertainment & Media)

  • A movie review site, where categories might be genre names (Action/Adventure, Comedy, Drama)

  • A magazine, where categories might be column names (Question & Answer, Letters to the Editor, Arts & Entertainment)

  • A project site, where categories might be project names (Revolt Dress, Merry Wife Apron)

In addition, Movable Type allows you to assign multiple categories to one entry. So in the case of the movie review site, you might even wish to use two different types of category archives: one categorized by genre and one categorized by the first letter of the movie title (A, B, C, etc). Or, in the case of the magazine, one set of categories could be section names and the other issue names; so you could categorize your entries by column name ("All Arts & Entertainment Stories") or by issue name ("All Stories from the May 2002 Issue").

In all these cases, the only work you have to do is to create the categories, and assign each entry to one or more categories; Movable Type will manage your archives for you.

8.3.2 Multiple Archive Templates

An archive template defines the layout of your archive pages and the "slots" into which your archived entries will be placed. For each archive type that you use, you can associate one or more archive templates with that archive type. This allows you to create multiple views of the same set of archived entries. For example, you might wish to provide a standard set of HTML archives, along with a printer-friendly set of archives; or perhaps you wish to cater to an older readership so you also might provide a large-font set of archives.

In any case, creating multiple archive templates is a simple matter of defining a new archive template, and associating it with the archive type of your choosing.

For this example, we will create an RSS feed for each category in the Movable Type system. As discussed in Section 5.8 in Chapter 5, syndicating your entries to an RSS feed allows users to easily determine when you have added a new entry. Suppose your site discusses several programming languages (Perl, Python, and Ruby) and devoted readers interested in your Perl stories may not wish to read your syndicated Python stories (in fact, they may become upset when you even mention Python). Therefore, you wish to create separate RSS feeds for your content — one RSS feed each for Perl, Python, and Ruby.

Assuming you have already categorized your entries into Perl, Python, and Ruby categories, this is easy.

  1. Log in to Movable Type and select the blog containing your entries.

  2. Click the Templates button to manage your templates.

  3. Click on the Create New Archive Template link.

  4. Set the name of the archive template to RSS Archives, and set the body of the template to the following:

    <?xml version="1.0"?>
    <!-- generator="Movable Type/<$MTVersion$>" -->
    <rss version="0.91">
      <channel>
        <title><$MTBlogName encode_html="1"$>: <$MTArchiveTitle$></title>
        <link><$MTArchiveLink$></link>
        <description>My <$MTArchiveTitle$> Entries</description>
        <language>en-us</language>
        <webMaster></webMaster>
        <lastBuildDate><MTEntries lastn="1">
    <$MTEntryDate format="%Y-%m-%dT%H:%M:%S"$><$MTBlogTimezone$>
    </MTEntries></lastBuildDate>
    <pubDate><$MTDate format="%Y-%m-%dT%H:%M:%S"$><$MTBlogTimezone$>
    </pubDate>
    <MTEntries lastn="15">
        <item>
          <title><$MTEntryTitle encode_html="1"$></title>
          <description><$MTEntryExcerpt encode_html="1"$></description>
          <link><$MTEntryLink$></link>
        </item>
    </MTEntries>
      </channel>
    </rss>
  5. Save the template.

  6. Click on the Blog Config button to edit your blog configuration.

  7. Click the Archiving link in the top right subnavigation.

  8. Click the Add New... button, which will open a pop-up window in which you can add a new archive template.

  9. In the pop-up window, for the Archive Type select Category, and for the Template select RSS Archives (the template you created in Step 4).

  10. Click Add.

  11. After the pop-up window closes and the page refreshes, you see that the new archive template has been associated with your Category archives. Now we just need to create a unique page name for each archive file to distinguish it from your standard HTML category archives.

  12. In the Archive File Template column, for the RSS Archives template, paste in the following:

    <$MTArchiveCategory dirify="1"$>.rss

    The dirify attribute means that the category label (for example, "Perl") will be transformed into a string suitable for use in a directory or filename. This doesn't matter if your categories are single words, but if one of your categories had been named "Common Lisp," it wouldn't do to have the space in the filename; therefore, it would be transformed into common_lisp, and the archive filename would be common_lisp.rss.

  13. Click Save.

That's it! Whenever you rebuild your category archives add a new entry, the RSS file for the appropriate category will automatically be rebuilt. The RSS file is named based on the name of the category, with the extension .rss; the generated files will be placed in your Local Archive Path (the setting from the Blog Config screen), and the URL will be your Archive URL (also in the Blog Config screen) plus the filename. For example, if you have a category called "Perl", and your Archive URL is http://www.foo.com/archives/, the RSS file containing your syndicated Perl stories will live at http://www.foo.com/archives/perl.rss.

8.3.3 Archive File Templates

Archive File templates allow you to customize the URLs used for the archive pages on your site using standard Movable Type tags. We saw Archive File templates briefly in the previous section when we assigned a filename to the RSS Archives template. In that case, we were using Archive File templates to distinguish the RSS archive files from the standard HTML archive files. But Archive File templates can also be used to impose a hierarchical directory structure on your archives.

8.3.3.1 Date hierarchy

For example, suppose you blog daily and you have been writing your blog for two years. In the course of these two years, you are keeping daily archives of your blog, which means that in your archive directory, you have 730 (365 * 2) daily archive files. You are starting to feel overwhelmed by the large number of files in the directory.

Instead of storing all your daily archives in one directory, Archive File templates allow you to create a hierarchy for your archive files to populate. This makes your directory structure much more manageable, and it can also make your archive URLs prettier; instead of http://www.foo.com/archives/2002_05_04.html, you could have http://www.foo.com/archives/2002/05/04/.

To create this structure using Archive File templates, follow these steps:

  1. Log into Movable Type and select the blog containing your entries.

  2. Click on the Blog Config button to edit your blog configuration.

  3. Click the Archiving link in the top right subnavigation.

  4. In the Archive File Template column, for the Date-Based Archive template for Daily archiving, paste in the following:

    <$MTArchiveDate
    format="%Y/%m/%d/index.html"$>
  5. Click Save.

That's it! When you rebuild your daily archives, Movable Type will now automatically create the proper directory structure in your filesystem.

8.3.3.2 Categorized individual entries

By default, individual archive filenames are generated as a padded form of the numeric entry ID (000002.html, for example) and are stored directly in the Local Archive Path directory. You may wish for more descriptive filenames, however. For example, if you are using Movable Type to power a music review site, it would be useful if the filename corresponded to the name of the album being reviewed. And it would be even better if the archive file were located in a directory named based on the genre of the review. Instead of http://www.foo.com/archives/000002.html, you would like a sample archive URL to look like http://www.foo.com/french/comic_strip.html.

To do this, follow these steps:

  1. Log into Movable Type and select the blog containing your entries.

  2. Click on the Blog Config button to edit your blog configuration.

  3. Click the Archiving link in the top right subnavigation.

  4. In the Archive File Template column, for the Individual Archive template for individual archiving, paste in the following:

    <$MTEntryCategory dirify="1"$>/<$MTEntryTitle dirify="1"$>.html
  5. Click Save.

When you rebuild your individual archives, the filenames for your reviews will now be based on the category assigned to the entry (e.g., "French") and the title of the entry (e.g., "Comic Strip").

Besides the more memorable URLs for your review archives, a side benefit of naming your individual archives using the entry title is that entry titles will not change unless you manually change them. The entry ID, on the other hand, could change if you ever need to move your entries from one blog to another using Movable Type's export and import mechanisms. Basing the filename on the entry title, rather than the ID, decreases the number of links to your site that will break if your entry IDs ever change.

8.3.3.3 Usage of existing syntax

Archive File templates use syntax that you already know to name your archive files: they use Movable Type tags. Each archive type has a set of tags that will work in Archive File templates — the working set of tags depends on the context of the archive. For example, when defining the Archive File template for category archives, you need to use the <$MTArchiveCategory$> tag to represent the name of the category being archived. A common mistake in this scenario is to use the <$MTEntryCategory$> tag, which will cause an error. <$MTEntryCategory$> does not work, because it assumes that a particular entry will be in context — that is, it is replaced with the category of the "current entry". In a category archive page, there is no "current entry" — there is only a set of entries corresponding to that particular category. So in that context, you must use the <$MTArchiveCategory$> tag.

8.3.4 Archiving by Calendar

Movable Type's calendar is completely customizable; it can be used as navigation through the most recent month's entries, as it is in the default templates; it can be used to power a calendar of events; it can be used to lay out an entire site, as it is by A Day Late (http://www.dollarshort.org/days/, as depicted in Figure 8-6); and it can even be used to emulate the output of the Unix cal program.

Figure 8-6. A Day Late calendar
figs/blog_0806.gif

A Day Late uses a combination of Movable Type and PHP to generate a calendar of daily links. On each day, there can be zero or more links, and all the links appear in the calendar square corresponding to that day. This behavior differs from more traditional web calendars, where each calendar square links to a listing of posts from that day or the latest post from that day. In this case, the entries are displayed directly in each calendar square.

In this example, we will create a template for an event calendar similar in style to the calendar at A Day Late, to demonstrate the use of the Movable Type calendar tags. If you run a news site with a list of events for each month, you might wish to generate your archives in calendar form rather than in the standard entry listing form used in the default templates. This example will generate event calendars for all of your monthly archives.

  1. Log in to Movable Type, and select the blog containing your entries.

  2. Click the Templates button to manage your templates.

  3. Click on the Create New Archive Template link.

  4. Set the name of the Archive template to Monthly Calendar, and set the body of the template to the following:

    <table border="1" cellspacing="1" cellpadding="0">
    <tr>
    <td colspan="7" align="center"><$MTArchiveDate format="%B %Y"$></td>
    </tr>
    <tr>
    <td align="center">Sunday</td>
    <td align="center">Monday</td>
    <td align="center">Tuesday</td>
    <td align="center">Wednesday</td>
    <td align="center">Thursday</td>
    <td align="center">Friday</td>
    <td align="center">Saturday</td>
    </tr>
    <MTCalendar month="this"><MTCalendarWeekHeader><tr></MTCalendarWeekHeader>
    <td valign="top">
        
    <MTCalendarIfEntries>
        <table border="0" cellspacing="0" cellpadding="5">
        <tr><td><$MTCalendarDay$></td></tr>
        <tr><td valign="bottom"><MTEntries><span class="excerpt"><a 
    href="<$MTEntryLink$>"><$MTEntryTitle$></a></span><br /></MTEntries></td></tr>
        </table>
    </MTCalendarIfEntries>
    <MTCalendarIfNoEntries><$MTCalendarDay$></MTCalendarIfNoEntries>
    <MTCalendarIfBlank>&nbsp;</MTCalendarIfBlank>
    </td>
        
    <MTCalendarWeekFooter></tr>
    </MTCalendarWeekFooter></MTCalendar>
    </table>
  5. Save the template.

  6. Click on the Blog Config button to edit your blog configuration.

  7. Click the Archiving link in the top right subnavigation.

  8. Click the Add New... button, which opens a pop-up window in which you can add a new archive template.

  9. In the pop-up window, for the Archive Type select Monthly, and for the Template select Monthly Calendar.

  10. Click Add.

  11. After the pop-up window closes and the page refreshes, the new archive template has been associated with your Monthly archives. Now just need to create a unique page name for each archive file, to distinguish it from your standard HTML category archives.

  12. In the Archive File Template column, for the Monthly Calendar template, paste in the following:

    <$MTArchiveDate format="cal-%m-%Y"$>.html
  13. Click Save.

That's it! Whenever you rebuild your monthly archives, or whenever you add a new entry, the monthly events calendar is rebuilt automatically. The calendar filename is based on the month and the year. For example, for the month of May 2002, the calendar filename is cal-05-2002.html.

    Team LiB   Previous Section   Next Section