Creating a private category


Today I hacked on MovableType to accomplish two things:

  • A private category that I could post without worrying that my stuff goes public

  • Sane URLs instead of those annoying date fields


Ok, really I was just trying to make sane URLs. But then these ended up overlapping and the act of making sane URLs allowed me to make private categories.

For my own version of sane URLs, I didn’t want to dirify every blog entry like some folks do, but I didn’t want to limit my entries to just their date like “http://…./2004/04/30/13.45.12/”

I realized that what I really wanted was to allow certain blog entries that have important information to have special URL suffixes like “how_to_fix_your_car” and have most other entries just appear with the date.

The way I’ve been doing conditional meta information is with Brad Choate’s excellent Key Values plugin. I decided that I would add a keyword, shortname to the Keywords field, which would designate the shortened url name. So for instance, you could put
shortname=creating_a_private_category

in the Keyword field, and that would become the end of the magic url. But then the other problem became, where to put this entry? I decided that the primary category of the entry made the most sense, so that this post ends up as /archives/projects/creating_a_private_category

So to do that, I edited the Individual Archive File template name in Weblog Config->Archiving. To start, I made it:

<MTKeyValues source="[MTEntryKeywords]"><MTIfKeyExists key="shortname"><MTEntryCategory>/<MTKeyValue key="shortname"></MTIfKeyExists><MTIfNoKeyExists key="shortname"><$MTEntryDate format="%Y/%m/%d/%H.%M.%S"$>&lt/MTIfNoKeyExists>&lt/MTKeyValues>/index.html

This allows the entry to go into /archives/<category>/<shortname> if there is a shortname, and into /archives/<date> if not.

So this was pretty huge, and it accomplished my goal of making sane URLs. It did strike me that this means some of my entries are kind of scattered about in the archive structure. However, this inspired me to password protect any “private” category directories. Since a bunch of individual entries were now going into special category-specific directories, I wondered if perhaps there was a way to make all the date-based archives for those categories go there as well. Sure enough, there is.

I got my hands on another Brad Choate specialty: the Supplemental Category Tags plugin. I needed this for . My plan was that any category that had “private” in the name would automatically go into a private category. For instance, I could say:
<MTIfNotCategory pattern="private">.. </MTIfNotCategory

And I could use that in my Individual Archive Template url:


<MTKeyValues source="[MTEntryKeywords]"><MTIfKeyExists key="shortname"><MTEntryCategory>/</MTIfKeyExists><MTIfCategory pattern="private"><MTEntryCategory>/</MTIfCategory><$MTEntryDate format="%Y/%m/%d/%H.%M.%S"$></MTIfNoKeyExists></MTKeyValues>/index.html

The problem I ran into here is that in MySQL, that field is a VARCHAR(255) and thus couldn’t hold the complete URL template. And VARCHAR can’t get any bigger than 255 characters. Well, it turns out that it is totally safe to just change that field to a TEXT. Now I have that giant Individual Template field, and everything works. anything private without the shortname keyword is forced into the private, password protected directory.

Now that the individual archives are stored in the right place, the last thing to do was to make sure that the normal listings (i.e. main index, archives, etc) didn’t show these entries. The trick here was to use the <MTIfNotCategory> tag again, and just wrap it inside every place where I saw .

I’m not incredibly psyched about this solution because it does wierd things. For instance, if I say <MTEntries lastn=10><MTIfNotCategory pattern="private">... and 5 of the last 10 entries are private, then only the other 5 appear. I wish that the <MTEntries> tag was simply smart enough to be able to use NOT for the category parameter.

Oh well. Maybe now that I’ve got public and private blog entries, I can actually start making some public ones. :)

  1. No comments yet.
(will not be published)