Help - Search - Members - Calendar
Full Version: Category Help
Movable Type Community Forum > Additional Resources > Tips and Tricks
justjaimelyn
Hi,  I want to list the categories in a table to the side of the blog.  Is there a code that will allow me to list the categories and allow people to click on the category they want to read.

Also, how do you leave a link to the category in the post?  I want people to be able to know what category this post goes into.

Anyone know how to do this?
pwinn
Be careful about putting a list of categories on non-index pages. If you've got a lot of categories and rebuild all of your pages, MT has to recalc the list of categories for each page, and it can chew up some time.

That said, the information you're looking for is in the MT docs. For example:
CODE
<MTCategories>
 <a href="<$MTCategoryArchiveLink$>"><$MTCategoryLabel$></a><br>
</MTCategories>

That should give you a list of your categories, with each category name as a clickable link to go to that category's archive page. You can include other information in there too, like <$MTCategoryCount$> to get a report of how many posts are in each category.

Here's one of the best ways to make a category link, one which allows for multiple categories. Edit whatever template you're using (Date-based, Invidual, whatever) and insert the following code within the MTEntries section:
CODE
<MTEntryCategories glue=", ">
<a href="<$MTCategoryArchiveLink$>"><$MTCategoryLabel$></a>
</MTEntryCategories>

That should give you clickable links wherever you want them.

Enjoy!
adamrice
I believe you can save most of that recalculating (which I haven't noticed) by moving the category menu into a template module, and calling that from all your pages using MTInclude (see the documentation).
justjaimelyn
Okay, that is just what I needed and it worked for my list of categories!

Thank you a billion times.  You are a genius!
pwinn
justjaimelyn, Woohoo! I'm glad it worked for you.

adamrice, you're right. I initially encountered a problem before those were introduced, back when I had a list of archive months on each entry page. Painful, that was, and I occasionally exceed my ISP's per-process limits.

I forgot that this had been solved by the modules, since I'm no longer listing the monthly archives this way. I am using those modules for about a dozen different things, though, so I was just being foolish.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.