Scott Andrew - lo-fi acoustic pop superhero!

Join the Demo Club to unlock new music, get discounts, tour dates and other neato stuff:

or learn more here.

March 1, 2003

MT Exclude Categories

…or, “How to Waste a Saturday.” It’s been a long time since I did any hacking with Movable Type, but necessity forced me to look into the plugin architecture. Specifically, MT allows you to limit posts by category by using the category attribute of the MTEntries tag. What I needed was the reverse: the ability to exclude posts by category.

The closest solution I’ve found in the wild is Staggernation’s FilterCategories plugin, which doesn’t affect MTEntries but instead suppresses specified categories in a list of categories, not posts.

So, after much bumbling around and cursing the vagueness of Perl, I came up with a miserable, miserable hack: an Exclude Categories plugin. This plugin creates a new container tag called MTEntriesExCat, which behaves exactly as MTEntries does, except that it reverses the functionality of the category attribute, excluding posts that fall under the listed categories. You can still use the Boolean AND or OR syntax (but not both at the same time) to specify multiple categories:


<MTEntriesExCat category=”Didacts AND Narpets”>

</MTEntriesExCat>

There’s a known problem with it. It doesn’t play too well with the lastn attribute. For example, let’s say that you specified the following in your template:


<MTEntriesExCat category=”Foo” lastn=”10″>

Now, if your last four posts were in category “Foo,” you’d only see six posts, not ten. Why? Because there’s no way (yet) to give MT a NOT query, like “give me the ten latest posts NOT in category Foo.” So what happens is that MT hands back the last ten posts, then the plugin sorts that result set, throwing away posts from the offending categories.

And that is why it is a miserable, miserable hack. But it works pretty well if you use days instead of lastn, or to supress posts from special categories you only use occassionally.

If you’re feeling particularly brave, you can change the tag name in the Perl file from “EntriesExCat” to “Entries,” thus overwriting the native MTEntries tag. If you do this, bear in mind that the category attribute will be reversed everywhere you use it with MTEntries. Don’t say I didn’t warn you.

Download Exclude Categories plugin (2K Zip file).

No Comments on “MT Exclude Categories”

Leave a Comment

Close
  • E-mail
  • Social Web

Email this page to a friend:

E-mail It

Buy Music

Download Scott Andrew tracks from iTunes Find Scott Andrew at Rhapsody Find Scott Andrew at Amazon Find Scott 
Andrew at CD Baby

New Videos

More Videos

Photos

More Photos at Flickr

Recent Reader Comments

  • Dave: $1 for the bonus tracks? BOOM! I'm there.
  • Shelby: you're a phenomenal artist. definitely going on th...
  • Steve Rydz: Great song Scott, good to hear something new. Kee...
  • Volker: Really good song! I am curious about the bonus ver...
  • scottandrew: Thanks for the comments, everyone. Hopefully I'll ...