LIBlogs

« Making Your Sidebar an MTInclude | Main | Changing the Basic Look of Your Blog »

Working with Categories

Movable Type gives you the option to organize your postings into categories. This can be very useful for certain types of blogs.

There are a few parts to working with Movable Type Categories. The first is mandatory, while the others are optional enhancements:

  1. Creating categories and assigning them to each posting
  2. Displaying category totals in your sidebar
  3. Adding the "posted to" category label to each posting

Creating categories and assigning them to each posting

1. Select "Categories" from the menu bar.

Categories menu

2. Create a category.

Select "Create New Top Level Category" and fill out the form.

Create new category

Rebuild your site when you are done.

If you wish to create a subcategory of a top level category, click on Create.

Create a subcategory

3. Assign a new entry to the desired category.

When you create a new entry, to the right of the Title window is a dropdown menu for selecting a category to assign to this entry. Select the appropriate category from the list.

Note that you can also add a new category here.

Assign category

Displaying category totals in your sidebar

Displaying a total of postings assigned to each cagetory is a nice enhancement.

Category count

1. Locate the category code.

Open your Templates window. From there, you will need to select which templates to open and modify.

By default, your sidebar code will be in your Main Index template. This is located in the Indexes window.

Main Index template

You may also have pasted this code into archive templates or other files that you maintain in your blog. If this is the case, you will need to add the new category code to all the files that contain your sidebar code.

Alternatively, you may have placed your sidebar code into a separate template module, and are using the MTInclude function to insert the code from this central location into multiple templates. If this is the case, you will need to add the new category code only in this one template module. For more information, see Making Your Sidebar an MTInclude.

This is the first part of the categories code.

<MTIfArchiveTypeEnabled archive_type="Category"><div class="module-categories module">
<h2 class="module-header">Categories</h2>
<div class="module-content">
<MTTopLevelCategories>
<MTSubCatIsFirst><ul class="module-list"></MTSubCatIsFirst>
<MTIfNonZero tag="MTCategoryCount">
<li class="module-list-item"><a href="<$MTCategoryArchiveLink$>" title="<$MTCategoryDescription$>"><MTCategoryLabel></a>
<MTElse>
<li class="module-list-item"><MTCategoryLabel>
</MTElse>
</MTIfNonZero>

2. Add the cagetory count code.

<MTIfArchiveTypeEnabled archive_type="Category"><div class="module-categories module">
<h2 class="module-header">Categories</h2>
<div class="module-content">
<MTTopLevelCategories>
<MTSubCatIsFirst><ul class="module-list"></MTSubCatIsFirst>
<MTIfNonZero tag="MTCategoryCount">
<li class="module-list-item"><a href="<$MTCategoryArchiveLink$>" title="<$MTCategoryDescription$>"><MTCategoryLabel></a>
(<$MTCategoryCount$>)
<MTElse>
<li class="module-list-item"><MTCategoryLabel>
</MTElse>
</MTIfNonZero>

Alternatively, you can also place (<$MTCategoryCount$>) before the </a> if you want the number to be a part of your hyperlink.

3. Save and Rebuild your template.

Adding the "posted to" category label to each posting

It can be helpful to show the "posted to" category accompanying each posting along with the other data such as the time of posting, comments, etc. This text will link to the archive page that displays all the postings assigned to that category. Here's how.

Posted to

1. Find the code location for inserting the category label.

Open your Templates window. From there, open your Main Index template. Locate the closing tag </MTIfPingsActive>.

<MTIfPingsActive>| <a href="<$MTEntryPermalink$>#trackback">TrackBacks (<$MTEntryTrackbackCount$>)</a></MTIfPingsActive>
</p>

2. Paste the new code just before the </p>.

<MTIfPingsActive>| <a href="<$MTEntryPermalink$>#trackback">TrackBacks (<$MTEntryTrackbackCount$>)</a></MTIfPingsActive>

<br />Posted to <MTEntryCategories glue=" | ">
<a href="<$MTCategoryArchiveLink$>"><$MTCategoryLabel$> </a></MTEntryCategories>

</p>

You may or may not wish to precede the new text with the <br /> tag. You will have to experiment with your layout to see what works best.

3. Save and rebuild your Main Index template

4. Make this modification to any archive templates you have activated on your blog.

Post a comment