Supplemental Category Tags
Here's a little plugin that provides some new Category tags for Movable Type.
Availability
You can download this plugin from here: mtcatx-1_5.zip
Requirements
The following are requirements for using this plugin:
- Movable Type 2.21 or later
- MT-Regex (if using the 'pattern' attribute of the IfCategory or IfPrimaryCategory tag).
Installation
To install, place the 'catx.pl' file in your Movable Type 'plugins' directory. The 'catx.pm' file should be placed in a 'bradchoate' subdirectory underneath your Movable Type 'extlib' directory. Your installation should look like this:
- (mt home)/plugins/catx.pl
- (mt home)/extlib/bradchoate/catx.pm
Description
This plugin provides additional tags for Movable Type categories.
Tags made available through this plugin:
- <MTCategoryNext>: Container tag for finding the next category relative to the current entry category or archived category.
- <MTCategoryPrevious>: Container tag for finding the previous category relative to the current entry category or archived category.
- <MTIfCategory>: Used to output content if the current category (in the context of a category archive template) matches a given name or pattern. Or if used within the context of an entry, will compare against all the categories assigned to that entry.
- <MTIfPrimaryCategory>: Much like 'IfCategory', but only compares with an entry's primary category.
- <MTEntryAdditionalCategories>: Similar to the Movable Type 'MTEntryCategories', but only lists secondary categories.
<MTCategoryNext>, <MTCategoryPrevious>
Attributes
- show_empty: Set to '1' to allow the selection of emtpy categories.
Usage
Here's the snippet you would add to the default Category Archive template (place right above the <MTEntries> tag):
<div id="menu">
<MTCategoryPrevious>
<a href="<$MTCategoryArchiveLink$>"> «
<$MTCategoryLabel$></a> |
</MTCategoryPrevious>
<a href="<$MTBlogURL$>">Main</a>
<MTCategoryNext> |
<a href="<$MTCategoryArchiveLink$>">
<$MTCategoryLabel$>
»</a>
</MTCategoryNext>
</div>
The next and previous category is selected based on alphabetic order.
<MTIfCategory>, <MTIfNotCategory>, <MTIfPrimaryCategory>, <MTIfNotPrimaryCategory>
Attributes
- name: Used to compare against a specific category name.
- pattern: Compares the category name(s) to a regular expression (requires the MT-Regex plugin).
Usage
<MTIfCategory name="Special">
<img src="images/special.gif" align="right" />
</MTIfCategory>
<MTEntryAdditionalCategories>
Attributes
- glue: Separator to place inbetween multiple categories.
Usage
Also filed under:
<MTEntryAdditionalCategories glue="; ">
<$MTCategoryLabel$>
</MTEntryAdditionalCategories>
License
Released under the MIT license. Please see
http://www.opensource.org/licenses/mit-license.php
for details.
Changelog
- 1.5: Added 'Not' support for IfCategory, IfPrimaryCategory tags.
- 1.4: Added 'EntryAdditionalCategories' container tag.
- 1.3: Added 'IfCategory', 'IfPrimaryCategory' tags.
- 1.2: Explicity sorting category list by label now.
- 1.1: The 'Next' and 'Previous' tags now exclude empty categories by default. The 'show_empty' attribute was added to allow them to be selected.
- 1.0: Initial release
Great! thank you :)
Hey Brad!
Nice Tags, I've been waiting for this long time, so thanx for this one.
But: is it a bug or a feature: if you have categories with nothing in it, they are also displayed, and (as there is nothing in, there's no archive-page for them) the link point to an error page (not found), certainly. ???
Nico-- The 1.1 update takes care of this.
I tried this plugin...it's great...except that it doesn't list my categories alphabetically. I am not sure how it is picking them up but I'm not getting the next and prev category that would fall alphabetically.
Is this a bug? I copied the code directly from the example. (I've taken off my site till I understand how it is working.)
Thanks!
Just a guess, but it appears (I say appears) to be linking between my categories in the order they were created.
rayne, Damelon: yes, that was a bug. 1.2 fixes that. Either mysql was sorting alphabetically for me or I haven't added any new categories since my Berkeley DB-to-mysql conversion (assuming that it created the categories in alphabetic order during the conversion). In any case, I didn't see any problem with the ordering myself. Try 1.2 out and see if it fixes yours.
Well, thanks for fixing it so fast, but I wasn't complaining. I had actually noticed the order it was displaying in and it didn't strike me as a pressing issue. Considering your lightning turnaround I was just going to let it be for a couple days. I would have mentioned it Monday or so, but I wasn't worried about any programming evil on your part. Have a nice weekend!
Brad, thanks for getting that fixed so quickly!
Great job on the category tags. Just curious tho: is there a way to use this with the MTElse tags?
Thanks again for the quick response on the forums!
The MTIfCategory tag dies if there are posts with no categories set (including the primary category). I got this error on rebuilding:
It doesn't really stop me from doing anything (all of my posts should have at least one category), but I thought you might like to know.
You are a genius!
Once again I think, "I wish MT could do this..." I come to your site and you have created a plugin for exactly what i need. Keep up the good work!
Is there a way to negate the name value for the IfCategory and IfPrimaryCategory tags?
I would like to wrap my entry section in the main index in these to avoid posting a certain category to the main index. Can this be done like this or should I be doing it a different way?
I think you can use the glue attribute instead of the name attribute in IfCategory to do an all but one inclusive. Or you could hack it...
Must you convert your blog to .php for this to work? Or can it be .html?
Thank you. =)
Yes, this plugin works with regular .html files.
is there a way I can use this in combination with something so I can have two instructions, eg
I'm already using php to use different stylesheets depending on the entry category, but using php in the templates leaves huge empty amounts of whitespace. And I don't like that :)
Hi Brad,
Thanks for the great info and the tools.
Any chance you'll be adding a <MTIfCategoryElse> or <MTIfCategoryDefault> tag - something as a catchall if the If's fall through? I'm going to use this with a dynamic template module loader and am too lazy to create a template for every category...
Thanks again,
Jeff Beer
Hey Brad,
There's no reason why this plugin should not affect Archive File Templates is there?
I am trying to write out individual archives into a directory structure that follows one of two patterns:
1) /category/title
2) /category/subcategory/title
There will always be a category and title and only sometimes a subcategory. When there is a subcategory, there will only be one.
Hence, in my archive file template for my individual archive looks like this relative to blog root (line feeds for readability):
<$MTEntryCategory dirify="1"$>/
<MTIfNotEmpty var="EntryAdditionalCategories">/<$MTEntryAdditionalCategories$>/</MTIfNotEmpty>
<$MTEntryTitle dirify="1"$>
I know I need to dirify the secondary category, but for now, I am just trying to get the above to work... It ain't...
Instead, I am gettnig fun errors like these upon rebuild:
MT::App::CMS=HASH(0x835fd58) Use of uninitialized value in concatenation (.) or string at /home/jallen/www/mt-staging/extlib/File/Spec/Unix.pm line 78.
MT::App::CMS=HASH(0x835fd58) Use of uninitialized value in hash element at /home/jallen/www/mt-staging/lib/MT.pm line 396.
MT::App::CMS=HASH(0x835fd58) Use of uninitialized value in hash element at /home/jallen/www/mt-staging/lib/MT.pm line 306.
Any ideas?
Thanks for creating this very useful plugin. Any chance you could add a 'MTCategoryFirst' and 'MTCategoryLast' feature?
MTs own MTElse doesn't seem to work within MTIfCategory - are you aware of this?
I'm trying:
MTIfCategory name="Hot Topic" -> Show special graphic
MTElse -> Show normal grapchic
/MTElse
/MTIfCategory
Also - this doesn't work:
MTIfCategory name="Hot Topic" -> Show special graphic
/MTIfCategory
MTIfNotCategory name="Hot Topic" -> Show normal graphic
/MTIfNotCategory
Hot Topic entries show have boths "graphics", while all others have none at all.
Sollution?
--
Morten, Denmark
(you're welcome to contact me directly by email)