Help - Search - Members - Calendar
Full Version: Categories w/o Entries
Movable Type Community Forum > Additional Resources > Tips and Tricks
eduardo
Hi there! I'm trying to list all the categories in a blog regardless of whether they have entries or not. The way I found out how to do it is by using the show_empty attribute in the MTCategories tag:
CODE
<MTCategories show_empty="1">
<p><a href="<$MTCategoryArchiveLink$>"><$MTCategoryLabel$></a> (<$MTCategoryCount$>)</p>
</MTCategories>

See the result in our Community Guide main page.

The problem with this is that if you click on the link for a category that has no entries, there will be no category archive, and you'll get a "Page Not Found" error. (In fact, the User Manual gives a warning about this very problem: "Note that this is [not] advised if you are including links to your category archive pages, because archive pages are not generated for empty categories. Thus, the archive link for an empty category will be a broken link.")

I was hoping there was a way to prevent the link from showing up if the category archive is empty. I tried to do it by using Brad Choate's MTIfNotEmpty tag to test whether there were entries, and then producing a link if there were, but not producing a link if there weren't (see my post elsewhere), but that approach doesn't seem to work.

Anyone have any suggestions on how else I might go about preventing the links from showing up for empty categories?

Thanks.
girlie
See if you like this. It requires PHP though.

I spent the day browsing old threads.  tongue.gif
eduardo
Thanks Girlie! ... And sorry for the trouble. I'm not familiar with PHP, wasn't sure whether I was set up for it, and it seemed like too much to deal with -- so I decided that I wouldn't show the empty categories after all.
girlie
Aha, the new Compare plugin to the rescue!!

CODE
<MTCategories show_empty="1">
<p><b><MTIfNotEqual a="[MTCategoryCount]" b="0" numeric="1">
<a href="<$MTCategoryArchiveLink$>">
</MTIfNotEqual>
<$MTCategoryLabel$>
<MTIfNotEqual a="[MTCategoryCount]" b="0" numeric="1">
</a>
</MTIfNotEqual>
</b> (<$MTCategoryCount$>)</p>
</MTCategories>


Way to go Kevin!!!!
vandahm
QUOTE
I'm not familiar with PHP, wasn't sure whether I was set up for it, and it seemed like too much to deal with -- so I decided that I wouldn't show the empty categories after all.


There's an easy way to find out if you're set up for PHP.  Create a file that contains only this line:
CODE
<? phpinfo(); ?>


Give the file a .php extension (filename.php).  Now, place the file on your webserver and try to access it with a web browser.  If PHP works, you should see a description of the capabilities that were compiled into PHP by your system administrator.
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.