« Printer-Friendly Pages | Main | Recent Comments »

Adding a "Posted to Category" Line

mtbadge-small.gif The default settings for Movable Type include category archiving. If you assign categories to your posts, you may want to include that information in the "Posted by" section underneath each entry. This is quite easy to do.

In the Main Index template, find the following block of code:

<p class="entry-footer">
<span class="post-footers">Posted by <$MTEntryAuthorDisplayName$> at <$MTEntryDate format="%"$></span> <span class="separator">|</span> <a class="permalink" href="<$MTEntryPermalink$>">Permalink</a> <MTIfCommentsActive>| <a href="<$MTEntryPermalink$>#comments">Comments (<$MTEntryCommentCount$>)</a></MTIfCommentsActive> <MTIfPingsActive>| <a href="<$MTEntryPermalink$>#trackback">TrackBacks (<$MTEntryTrackbackCount$>)</a></MTIfPingsActive>
</p>

Add the following code before the closing closing p tag of the code above.

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

Save and rebuild your Main Index template.

In your Individual Entry Archive Template, find the following code:

<p class="entry-footer">
<span class="post-footers">Posted by <$MTEntryAuthorDisplayName$> on <$MTEntryDate$></span> <span class="separator">|</span> <a class="permalink" href="<$MTEntryPermalink$>">Permalink</a>
</p>

Add the following code before the closing span tag or p tag of the code above.

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

Save template and rebuild your files.

Comments (11)

If you want to show Cateogry/SubCategory relationships (eg. Parent » Sub), use this code


<MTEntryCategories glue=", ">
<MTParentCategories glue = "&raquo; ">
<a href="<$MTCategoryArchiveLink$>"
title="<$MTCategoryDescription$>"><$MTCategoryLabel$></a>
</MTParentCategories>
</MTEntryCategories>

Any idea on how you would only show subcategories?

Swift Author Profile Page:

For the code on the individual archive template, does that only work if the archives are static? I'm using dynamic publishing for my archives, but for some reason can't get the code to work in my individual archive template.

Anyone know how I would be able to show just the parent category for an individual archive entry?

Yes how does one only show the entry's subcategory. MT's documentation is so sparse.

I tried Arvind's code on my website (www.notforsheep.org) and for some odd reason, it spits out the results in triplicate. Any ideas on how to just get the code to show one single result, i.e. PhD Stuff >> Fall 2007 >> Public Admin? Thanks! :-)

Wow. That is weird. I have no idea what might be causing it. Have you posted it at the MT forums?

I don't know a whole lot about MT, so I might be wrong, but this only worked for me when I added </a></MTEntryCategories>
to the end of the code you say to cut and paste into the main index template.

MSD:

does this code apply to MT 4?

@MSD -

There shouldn't be anything version-specific to any of this code.

Kass:

I'm looking for a way to show all of the parent categories, then list the child categories right after. Arvind's code in the first comment is close, but not quite what I'm after. This is basically what I want:

parent >> child, child, child
parent2 >> child, child, child

Any way to do this?

Using MTOS, in case that has some new tags or whatnot that will enable this...

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.)