Movable Type Plugin: MTAgain
What is MTAgain? Why do we need it?
MTAgain provides looping to Movable Type. For example, say you want to list not only the previous blog entry, but the one before that and the one before that. MTAgain lets you do that. Essentially, what it can do is put a tag like MTEntryPrevious inside itself, and it can do that thousands of times if you're crazy enough to try it.
The MTAgain plugin for Movable Type is not my own creation. Someone named Lummox JR wrote it years ago, and then disappeared. In fact, I couldn't find his original plugin anywhere – even the Web Archive didn't have copies of his long-gone Web site!
What I did find was an article that mentioned the plugin and, when readers complained that the plugin didn't exist anymore, offered the code. However, they never offered an instruction manual. With the author's site gone and the manual missing, I had to do some sleuthing. In particular, I couldn't really guess what the "any" feature did. But I found an old forum post, learned the code, revised and expanded it, and now I offer it to you with a useful new feature.
If you just want to just skip the tutorial here, you can go ahead and download MTAgain 1.2 for Movable Type now. But if you want a quick overview of what this thing can do, read on.
The MTAgain plugin has been updated for Movable Type 3.x. It probably runs in 4.x but I wouldn't know. I revised it so that when you install it, it appears on the plugin page. And I gave it a new tag. Here is a review of what each tag offers:
This a container tag that you wrap around the code you want to repeat. The limit attribute is optional, but I suggest you include it. The old MTAgain plugin had a hard-coded limit of 50, so it was impossible to lock up a server with endless looping. That's great for safety, but it also makes it impossible to loop through thousands of blog entries. Since I wanted to do exactly that, this version of MTAgain has a limit of 1000. If you don't need it looping that deeply, you should set a limit.
This a token that you place in the spot where you want the code to repeat. This needs to be inside the MTAgain tags. This is a difficult concept for some. You are putting the code inside of itself. But it isn't that hard. Consider this code:
You've put the MTEntryPrevious tags inside the MTAgain tags, so the MTEntryPrevious tags are going to repeat. Where will they repeat? Where the MTAgainHere tag is – inside the MTEntryPrevious tag. This means it shows the name of the previous entry, then shows the name of the entry previous to that and so on. See?
This is a container tag that you wrap around the code you want to appear when the loop ends. The "any" attribute is optional. Since there are two ways to end the loop, the any attribute determines which ending it responds to. The first way a loop can end is that it peters out, never hitting your hard limit. For example, if you limit the loop to running 5 times but there are only 3 items to loop through, you never hit the hard limit of 5. In such a case, <MTAgainStop any="1"> will display your "it petered out" markup. However, if you need to display something when the hard limit IS reached, then you want a plain <MTAgainStop>. That will not run if it peters out, but it will run if the hard limit is reached and the loop is forced to stop.
This a new token tag that I've added. It's not a wrapper. You just place it somewhere and it kills the loop, even if the limit hasn't been reached. Used with normal MT tags it almost doesn't make sense – wherever you put it, it'll kill the looping immediately, so what's the point? Well, if you're using conditional tags, it gets much more interesting. Consider what happens when you couple this with the <MTIfEqual> tag from the Compare plugin:
<MTIfEqual a="[MTTagName]" b="rocknroll">
What does that do? To start, it keeps going backwards through previous entries – that's what MTAgain & MTAgainHere gets you. But notice the MTIfEqual tag – it's watching for a specific tagged entry. When it finds it, it prints out a link, followed by MTAgainBreak, which ends the loop. Thus, you can have a link to the "previous entry tagged as rocknroll." I'm sure you'll think up cooler applications.
Ready? Download MTAgain 1.2 for Movable Type 3.x. Have fun!