Help - Search - Members - Calendar
Full Version: Mt4 & Category / Sub-category Archive Lists
Movable Type Community Forum > Using Movable Type > Categories and Entry Tags
jbrotherlove
I am struggling with MT4 and the new Template/Tag structure. My current issue: I want to list all categories/sub-categories in a sidebar like so:

CODE
<h3>BUSINESS</h3>
<ul>
<li>Finance</li>
<li>Small Business
<li>Seminars
</ul>

<h3>NEWS</h3>
<ul>
<li>Press Releases</li>
<li>New Hires</li>
</ul>


By default the Category Listing (nested) widget almost works. But I only want to show the Category Label for Parent Categories and style them with h3 tags while styling the Sub-Categories as unordered lists. I hope that makes sense.

I tried mucking around with the existing widget code but I'm not doing something right. This is what I have so far. Only the Parent Categories show with it.

CODE
<MTIfArchiveTypeEnabled archive_type="Category">
<MTTopLevelCategories>
<mt:HasNoParentCategory>
<h3><MTCategoryLabel></h3>
</mt:HasNoParentCategory>
<mt:HasParentCategory>
<MTSubCatIsFirst><ul></MTSubCatIsFirst>
<li><a href="<$MTCategoryArchiveLink$>" title="<$MTCategoryDescription$>"><MTCategoryLabel></a>
</mt:HasParentCategory>
<MTSubCatIsLast></ul></MTSubCatIsLast>
</mt:HasNoParentCategory>
</MTTopLevelCategories>
</MTIfArchiveTypeEnabled>


I'm sure someone is doing something similar. But I can't find any examples.
carmige
j, here's the one I use. It's output is the format you would like to see it. Give it a try.

CODE
<MTIf name="module_category_archives">
<MTIfArchiveTypeEnabled archive_type="Category">
<div class="widget-categories widget">
<h3 class="widget-header">Categories</h3>
<div class="widget-content">
<MTTopLevelCategories>
<MTSubCatIsFirst>
<ul class="widget-list">
</MTSubCatIsFirst>
<MTIfNonZero tag="MTCategoryCount">
<li class="widget-list-item"><a href="<$MTCategoryArchiveLink$>"<MTIfNonEmpty tag="MTCategoryDescription"> title="<$MTCategoryDescription$>"</MTIfNonEmpty>><$MTCategoryLabel$> (<$MTCategoryCount$>)</a>
<MTElse>
<li class="widget-list-item"><$MTCategoryLabel$>
</MTIfNonZero>
<MTSubCatsRecurse>
</li>
<MTSubCatIsLast>
</ul>
</MTSubCatIsLast>
</MTTopLevelCategories>
</div>
</div>
</MTIfArchiveTypeEnabled>
</MTIf>
jbrotherlove
QUOTE (carmige @ Aug 26 2007, 05:27 PM) *
j, here's the one I use. It's output is the format you would like to see it. Give it a try.

Thanks for pitching in. Unfortunately that gave me the same default listing when, in fact, I want to top level categories to act as headers instead of list items. However, your suggestion inspired me to go through the (incredibly lengthy) Template Tag Reference where I discovered SubCategories. Using the SubCategories tag, I came up with the following working solution:

CODE
<h3>Business</h3>
<div id="sidenav">
<ul><mt:SubCategories category="Business">
<li><a
href="<$MTCategoryArchiveLink$>" title="<$MTCategoryLabel$>"><$MTCategoryLabel$></a></li>
</mt:SubCategories></ul>
</div>

<h3>Entertainment</h3>
<div id="sidenav">
<ul><mt:SubCategories category="Entertainment">
<li><a
href="<$MTCategoryArchiveLink$>" title="<$MTCategoryLabel$>"><$MTCategoryLabel$></a></li>
</mt:SubCategories></ul>
</div>

As you see, I'm not using any of MT's default widgetry (it's too much extra code for my taste). Next up, I try to understand the SubCategories sort_order attribute to see if I can place them in the arbitrary order desired by the client.

Never a dull moment.
PeteSwann
Did you ever figure how how to accomplish this task, without having to list each of the parent categories manually?

I am new to MT, and have been struggling with getting a Nested Category list for the past 8 hours!

Thanks,
Pete
jbrotherlove
Pete, I settled on hardcoding the main (parent) categories into headers and using the SubCategories tag to make the list:

CODE
<h3>Business</h3>
<ul><mt:SubCategories category="Business">
<li><a
href="<$MTCategoryArchiveLink$>" title="<$MTCategoryLabel$>"><$MTCategoryLabel$></a></li>
</mt:SubCategories></ul>

<h3>Entertainment</h3>
<ul><mt:SubCategories category="Entertainment">
<li><a
href="<$MTCategoryArchiveLink$>" title="<$MTCategoryLabel$>"><$MTCategoryLabel$></a></li>
</mt:SubCategories></ul>

I hope that helps you.
theblueduck
I am having a similar situation, but I need to have the top level also as a list item. However, I need to have my child subcategories use a different ul class. I haven't been able to figure out how to do this. Anyone have any ideas?
lex2000
Since this question is related I'm going to ask in this thread as opposed to posting a new topic. Please let me know if I should just post a new one, as I certainly don't intend to hijack the thread.

SO, I'm trying to do something similar except I do not want my sub-categories to list at all. I would like top-level category named "Archives" that is a link in a list on the sidebar with all of the other top-level categories. For example:

Baseball
Football
Hockey
Soccer
Archives


The five top-level categories are all that should appear, whereas right now this is what I get:

Archives
Baseball 08
Football 08
Hockey 08
Soccer08
Baseball
Football
Hockey
Soccer


I would also like to have "Archives" listed at the bottom but I'm going to guess that's not possible without reversing the entire order.

Any ideas or insight? Is this simpler than I'm making it?
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.