Help - Search - Members - Calendar
Full Version: Not Listing Categories That Have No Posts.
Movable Type Community Forum > Using Movable Type > Categories and Entry Tags
BloggyThingy
Using MT4.21, my list of categories includes those categories that do not have any posts. Is it possible to exclude these categories from the list?

This is the code that is generating the list items.

CODE
<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>


I'm guessing that I need to do something like put the MTCategoryCount tag in an MTIf, with a value of zero. I've tried a few things, and have looked at the online Help. I'm sure it's a simple thing to do, but nothing has worked. Any ideas?

Also, in the above code, what is the MTIfNonEmpty tag (in the list (li) tag actually doing? It seems to refer to the Description field of the categories. But the list is always rendered the same whether or not it's empty.

Thank you!
danwolfgang
In your code, 'MTIfNonZero tag="MTCategoryCount"' is already doing the count to decide how to list your categories. Notice the 'Else' is displaying if there are no entries in the category. So, this way, every category gets listed. Remove the else (as in the code below) and only those with counts should be in your list.

As for the descriptions and IfNonEmpty, note that they are put in the title attribute of the link. It shouldn't be displayed, unless you hover over it.

CODE
<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>

            </MTIfNonZero>
            <MTSubCatsRecurse>
                    </li>
            <MTSubCatIsLast>
                </ul>
            </MTSubCatIsLast>
</MTTopLevelCategories>
BloggyThingy
Hi Dan! Both answers are so obvious... not that you've pointed them out! Thank you! biggrin.gif
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.