Fuddland

Skip to site navigation

To further enhance the dynamic category pages, I wanted to take care of situations where a category was defined but no entries in that category had yet been made; ordinarily the page would be output with just a blank space where the entries were supposed to be, which isn’t particularly helpful to the user [it could easily be mistaken for a mis-loaded page, and refreshed a few times before they gave up and went elsewhere].

What was needed was a compliment to the <MTEntries> tag: an <MTIfNoEntries> tag. MT doesn’t have one as standard; a few googles later and I found that Jay Allen had wondered why, and the solution [but not the answer] had been left in his comments. I found nothing further anywhere else, so I just took the code Lummox JR had suggested, saved it as a file called ifnoentries.pl, uploaded to the plugins directory and bingo! I had a working <MTIfNoEntries> tag.


It currently doesn’t play nicely with SubCategories — for a parent category archive, if there are entries in the subcategories but none in the parent category alone, MTIfNoEntries will process whatever is between its opening and closing tags, which it obviously should not do. I’m not entirely sure how to go about fixing this.

Since I wasn’t the author I think it would be wrong of me to upload the plugin to the MT Plugin Directory, even on Lummox JR’s behalf, but the file is locally available if anybody wants to use it too. Rename it as ifnoentries.pl and upload it as you would any other plugin.

Example usage:

<MTCategories>

<h1><$MTCategoryLabel$></h1>

<MTIfNoEntries>
<p>Sorry, there are no entries in this category.</p>
</MTIfNoEntries>

<MTEntries>
<h2><$MTEntryTitle$></h2>
<$MTEntryBody$>
</MTEntries>

</MTCategories>


Update: Okay, just ignore everything in the above entry. There’s no need for this plugin — you just need Brad Choate’s IfEmpty plugin.

<MTCategories>

<h1><$MTCategoryLabel$></h1>

<MTIfEmpty expr="[MTEntriesWithSubCategories]1[/MTEntriesWithSubCategories]">
<p>Sorry, there are no entries in this category.</p>
</MTIfEmpty>

<MTEntriesWithSubCategories>
<h2><$MTEntryTitle$></h2>
<$MTEntryBody$>
</MTEntriesSubCategories>

</MTCategories>

The 1 between the [MTEntriesWithSubCategories] tags just ensures there is some output. [Figured out whilst I was trying to fix the “entries in subcategories but none in parent category” issue above.]

In: Indexed / GoogleAdsense & Site News

2004 / 03 / 07 – 14:42

Relative links: