« Related Tags | Main | Dynamic Comment Previewing »

How to Make a Subject Index Using Tags

index-example.jpg

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:

    <MTSearchResults>

    <MTBlogResultHeader>
    <h2>

    <MTIfTagSearch>
    Results for &quot;<$MTSearchString$>&quot;
    </MTIfTagSearch>
    </h2>

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


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

    </MTSearchResults>

    </MTIfTagSearch>

    <MTBlogResultFooter>
    </div>
    </MTBlogResultFooter>

    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:

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

    <MTIfTagSearch>

    <MTSearchTags>

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

    </MTSearchTags>

    </MTIfTagSearch>



  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>                                                          
                                 
     <MTTags>
    <li>
    <a href="<$MTCGIPath$>mt-search.cgi?tag=<$MTTagName$>&Template=the_name_of_your_tag_search_template&blog_id=<$MTBlogID$>"><$MTTagName$></a> (<$MTTagCount$>)
     </li>
    </MTTags>
    

  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:

    
    <MTEntryIfTagged>
    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>
    </MTEntryTags>
    </MTEntryIfTagged>
    

    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.

Links:
Everybody Loves Tags!

Comments (5)

Twist [TypeKey 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).

Elise [TypeKey Profile Page]:

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.

Elise [TypeKey Profile Page]:

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.

Post a comment

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