« Related Tags | Main | Dynamic Comment Previewing »

How to Make a Subject Index Using Tags


Updated August 23, 2006. Fixed a few things.

Most non-fiction books have a Subject Index in the back, making it easy for the reader to look up topics of interest, based on a word or term. With MT3.3's new tagging feature, you can create an alphabetical index of your entries tags. You can see this in action with LMT's Tag Index.

  1. Add tags to your posts.

    In the entry edit window, click on "Customize the display of this page" link at the bottom of the page. In the popup, select "Custom" and check the box marked "Tags". Now you should see a field for tags in your entry edit window. For each entry, add a tag or tags, separated by a comma. Try to avoid odd characters like apostrophes and ampersands. Decide on a capitalization scheme (either all lower case or the first letter is caps) and stick with it. Here's an example:

    Apples, James Madison, New York City

    Here are some tips for successful tagging:

    • Be specific. Pick words that are as specific as possible. For example "Gravenstein Apple" is more specific than "Food".
    • Be consistent. If you've tagged one post "The Netherlands," avoid tagging another post "Netherlands". Check your complete tag index to see if a tag has already been used.
    • Be redundant. Not every Chocolate-related post will also have Dessert as a keyword. But if at least one does, then the two subjects are related.
    • Tag all your posts, including your old posts. (If you have been using keywords as a way of tagging see Converting Keywords into Tags.)

  2. Make a new tag-only search results template.

    By default, MT3.3 uses the default Search Results Template (in System Templates) for tag results. So when you click on a tag displayed in an entry it triggers the mt-search.cgi script and a search result page is displayed with the titles and excerpts of the entries with that tag. You will want to create a tag-only search results template. The way to do that is to create an "Alternative Search Template". To do this, see the directions in the LMT tutorial MT Keyword Search. You can copy the default search template from Templates > System Templates. Paste it into a text editor and make adjustments on this template. Follow the directions in LMT for creating an alternate search template or the directions in the MT User Manual for Adding Alternate Search Templates.

    My basic tag search result template looks something like this in the main section:



    Results for &quot;<$MTSearchString$>&quot;

    <div class="search-results-container">

    <h3><a href="<$MTEntryPermalink$>"><$MTEntryTitle$></a></h3>
    <p><$MTEntryExcerpt$> <$MTEntryEditLink$></p>




    You may want to put a list of related tags in the side bar of the search results template. My sidebar related tags code (see Related Tags) uses the Tags Supplementals plugin and looks like this:

    <b>Other Tags Related to "<$MTSearchString$>"</b><br/><br />



    <li><a href="/tag/<$MTTagName encode_url="1"$>" rel="tag"><$MTTagName></a></li>



  3. Create an index of all of your tags.

    Create a new index template. Set the template to rebuild automatically. Copy and paste everything from your main index into the new template. Delete everything in the middle section of the template that has to do with entries (everything between and including the MTEntries opening and closing tags). In its place put the following code:

    <h3 class="title">Index</h3>                                                          
    <a href="<$MTCGIPath$>mt-search.cgi?tag=<$MTTagName$>&Template=the_name_of_your_tag_search_template&blog_id=<$MTBlogID$>"><$MTTagName$></a> (<$MTTagCount$>)

  4. Display tags in your entries.

    Within the MTEntries opening and closing tags on the Main Index and Archive templates, you can put the following code to list out the tags for the entry:

    Tagged:  <MTEntryTags glue=", ">
    <a href="/path/to/MT/mt-search.cgi?tag=<$MTTagName$>&Template=the_name_of_your_tag_search_template&blog_id=1"><$MTTagName$></a>

    Remember to swap out the path to your MT install, the tag search template, and the blog ID as in the previous step.

Many thanks to Mike Everett-Lane for the inspiration for this article.

Everybody Loves Tags!

Comments (7)

Twist Author Profile Page:

Tagging functionality could be vastly improved in MT. Instead of having to manually tag every entry it would be nice to just define a list of words that you want to be tags and anytime that word shows up in an entry it automatically gets that tag assigned. You could also have words that aren't tags themselves but that when included in an entry case a tag to be added (i.e. including the word "Xbox" might cause the tag "gaming" to be added to the entry).

Good feedback for Six Apart.

I feel like such a newbie when it comes to tags. A little tip though... /path/to/mt/ is probably better known as <$MTCGIPath$> ... lets MT do the work for you.

Oh, also... using <$MTBlogID$> is better than hardcoding it in there. The more work MT can do, the less I have to.

Hi Jesse,
When I upgraded to MT3.32 I changed the mt directory and poof, got lots of 404 errors because I had hard coded the MT path into my code. Thanks for pointing out that I could just have easily used the tag for the path (and the blog ID). Doh! It's all working again now. Whew.


I haven't found this documented anywhere, but I'm using Movable Type 3.35 and noticed that you can also plug in multiple blog id's.

So, I'm starting to use this on some of my templates to search for tags across multiple blogs:

<a rel="tag" href="<$MTCGIPath$>mt-search.cgi?tag=<$MTTagName$>&blog_id=1,2"><$MTTagName$></a>

The results page is even formatted nicely and places results under subheadings like:



(I'd link to an example... but my blog won't be finished for a couple of weeks still)

Hi Jim -

Though not well-documented, the search script has supported including or excluding multiple blogs for a while. Here's a page on doing so from 3.2.

Post a comment

(If you haven't left a comment here before, your comment may need to be approved before will appear on the entry. Thanks for waiting.)