Wednesday, June 28, 2006

Custom Fields

I spent enough time on this earlier today that I figured an entry was due. Most of the support forums were a disappointment, too, so let this serve as a reference for desperate souls like me who are hunting around for clues about how to integrate the Movable Type Custom Fields plugin in their weblogs. What follows will probably only be of interest to MT users. It's not entirely self-serving, though. I think we'll soon be using custom entries for CCC Online, and I wasn't having any luck getting it to work here until now.

The first problem I encountered was that the plugin was old. I had MTCustomFields 1.12 on the system rather than the updated v. 1.2. It's a fast upgrade; takes just a minute or two to get everything in place.

Here's what I wanted to do:  Basically, I wanted another field on the input screen that would allow me to designate Technorati tags for selected entries. I am already using the Keywords field for del.icio.us tagging. But I don't want anything to show up with entries where I'm not using any tags at all.  To accomplish this, I have to have the following plugins in my MT installation: MTLoop, MTGlue, and MTCustomFields.  And I'm running MT 3.2.

With these plugins, I concocted a sequence of tags that would link directly to my del.icio.us account.  With the following code, I can enter a string of tags in the Keywords field, separated by spaces, and get a list of links to the corresponding tags in del.icio.us.  The catch is that after posting the entry, I have to post the page to del.icio.us and copy/paste the same tags into the keywords field in del.icio.us.  That way the links on my weblog match up with the tags in del.icio.us.  Here's an example.  We're using the same system for CCC Online. And here is the code from the index template that makes all of this happen.  If you want the tags to show up in other templates (individual, monthly, category, etc.), just copy/paste this code there as well:

<MTIfNonEmpty tag="EntryKeywords">Tags: <MTGlueContainer><MTLoop values="[MTEntryKeywords]" delimiter=" ">
<a href="http://del.icio.us/dmueller/<$MTLoopValue$>"><$MTLoopValue$></a><MTGlue>, </MTGlue></MTLoop></MTGlueContainer><br></MTIfNonEmpty>

The MTIfNonEmpty enclosure tells MT to ignore everything here if I haven't entered any tags in the Keyword field.  No permanent elements will show up the individual entry. Everything depends upon there being tags.  No tags, no mess.

But I was after something else.  The del.icio.us tagging is a good fit for the way I use it, particularly when marking notes that I want to integrate with the other tagged items I drop into del.icio.us. How could I add a second layer of tags, a layer that would tie directly into Technorati? For this, I needed another entry field.  So I installed MTCustomFields. Everything was fine. The expanded interface is intuitive. I was able to add "Technorati" as an extra field. Still, I couldn't find many examples of the code to use in the index template. There were several examples of wonky, dysfunctional code. I was only able to learn the basic code for the enclosure and the field specification. It looks like this:

<MTEntryData>
<MTEntryDataTechnorati>
</MTEntryData>

It was a start.  But I still wanted to integrate it into the scheme I was using for del.icio.us which allows me to enter a string of tags and lets the MT engine do the rest.  I'm not a die-hard Technorati tagger, but it would be nice to have the flexibility of simply keying in a tag or two (teaching-carnival or Academy2.0) for certain entries.  For others entries, it's fine that they publish untagged (or untagged by anything beyond my only semidescript category labels).  By whisking together the two chunks of code from above, I was able to get something to work:

<MTEntryData><MTIfNonEmpty tag="EntryDataTechnorati">Technorati tags: <MTGlueContainer><MTLoop values="[MTEntryDataTechnorati]" delimiter=" "><a href="http://technorati.com/tag/<$MTLoopValue$>" rel="tag"><$MTLoopValue$></a><MTGlue>, </MTGlue></MTLoop></MTGlueContainer></MTIfNonEmpty></MTEntryData>

Note that "Technorati" matches with the name I used when I set up the extra field using MTCustomField.  What's peculiar is that the first tag reference doesn't use "MT" whereas the second tag reference does.  But it works (and with a bricoleur-shrug, I don't mind why right now). If I enter a list of tags in the Technorati field, they turn up at the bottom of the entry with live links. The entry interface looks like this:

Useful to someone else, maybe.

Bookmark and Share Posted by at June 28, 2006 4:15 PM to On Weblogs
Comments