Applications

RightFields 1.21

Spam Prevention

TinyTuring 1.02

Template Tags

CheckLinks 1.2

Collect 1.2

Columnize 1.11

Compare 1.1

DateTags 2.3

DaylightOrStandard 1.1

DropCap 1.1

FilterCategories 1.1

FirstNWords 1.3

GetXML 1.1

Glue 1.1

IfModified 1.4

Loop 1.1

TextWrap 1.1



Support staggernation.com's plugin development

FilterCategories Plugin for Movable Type

Current version: 1.1 (7/12/04)

About the FilterCategories Plugin

This Movable Type plugin implements a pair of template tags that allow you to filter a listing of categories by specifying the categories either to include in or to exclude from the listing.

Installation

To install the FilterCategories plugin, upload the file FilterCategories.pl to the plugins directory within your Movable Type directory. If you do not already have a plugins directory, create one before uploading the file. For more information about Movable Type plugins, see the documentation.

Support

Please use the support forums for all support requests, bug reports, feature requests, questions, and comments regarding this plugin.

What About Entries?

One feature that seems to be requested fairly often on the MT support forums is the ability to specify categories by exclusion—NOT in addition to AND and OR—in the MTEntries tag. Well, this plugin doesn't do that. Sorry.

Here's why. It's fairly easy to create a plugin tag that goes immediately within MTEntries and simply skips over any entries that belong to specified categories. The problem with "filtering from within" like this (which works fine with a simple category listing) is that MTEntries doesn't know which entries have been omitted, so the output of MTEntriesHeader/Footer, MTDateHeader/Footer, and MTEntryPrevious/Next will not be accurate, nor will the lastn attribute be respected. I don't think there's a good way to implement category exclusion without modifying the code of MTEntries itself. (MTEntryCategories had a similar problem, but that tag is simple enough that it seemed reasonable to provide a replacement version. With MTEntries, that would be unwise.)

MTFilterCategories

This container tag is intended to go within MTCategories or MTArchiveList (where archive_type="Category" or your default archive type is Category). It should be placed immediately within either of these tags. For each category listed, MTFilterCategories decides whether or not to display its contents based on the categories you specify in the include or exclude attribute. You must use either include or exclude, but you should not use both.

The tag takes the following attributes:

  • include="cat1|cat2|..." (optional)
    One or more category labels, separated by a | character. If you use this attribute, only those categories that appear in this list will be displayed.
  • exclude="cat1|cat2|..." (optional)
    One or more category labels, separated by a | character. If you use this attribute, only those categories that do not appear in this list will be displayed.
  • exclude_archive_cat="1" (optional)
    This only makes sense within a Category archive template. If you use this attribute, on the archive page for a given category, that category will be excluded from the listing.

If you happen to have the character | in any of your category labels, you can change the separator by modifying this line of code near the top of FilterCategories.pl:

$delim = '\|';

The following example displays all of your categories except Arts and Leisure and Entertainment:

<MTCategories show_empty="1">
 <MTFilterCategories exclude="Arts and Leisure|Entertainment">
  <a href="<$MTCategoryArchiveLink$>"><$MTCategoryLabel$></a><br>
  <$MTCategoryDescription$><br>
 </MTFilterCategories>
</MTCategories>

MTFilteredEntryCategories

This container tag is a replacement for MTEntryCategories. As that tag does, it lists the categories assigned to the current entry, but it allows some additional attributes that let you specify which categories should be displayed.

The tag takes the following attributes:

  • glue="gluetext" (optional)
    As with MTEntryCategories, a string to be used to separate the categories, such as a comma and space or a line break.
  • include="cat1|cat2|..." (optional)
    One or more category labels, separated by a | character. If you use this attribute, only those categories that appear in this list will be displayed.
  • exclude="cat1|cat2|..." (optional)
    One or more category labels, separated by a | character. If you use this attribute, only those categories that do not appear in this list will be displayed.
  • exclude_archive_cat="1" (optional)
    This only makes sense within a Category archive template. If you use this attribute, on the archive page for a given category, that category will not appear in the MTFilteredEntryCategories listing. This lets you do something like the following (within MTEntries on a Category archive template):
    Other categories for this entry:
    <MTFilteredEntryCategories glue=", " exclude_archive_cat="1">
     <a href="<$MTCategoryArchiveLink$>"><$MTCategoryLabel$></a>
    </MTFilteredEntryCategories>
    

Version History

7/12/04 - version 1.1

  • Plugin now registers itself with MT 3 interface.
  • Added $VERSION variable and package declaration.
  • All container tags now pass conditions along when building contents, so they'll work outside conditional tags within MTEntries, etc.

12/18/03 - version 1.05

  • Added exclude_archive_cat attribute to MTFilterCategories (Paul Baron)

7/18/02 - version 1.0 released


The End As I Know It: A Novel of Millennial Anxiety, by staggernation.com proprietor Kevin Shay, is now available in paperback.

Please visit kshay.com for more information.