MT:If in the Archive

< Last | Blog | Next >Meadow Hill / Blog / April 8

I had an interesting problem when I was creating my archive. While I wanted to create the page in a way I’d never seen before, I couldn’t get one detail figured out before it went live.

While I’ll never claim to be a master at Movable Type, I sure like how I’ve bent it to my will. In the last year I made everything work just as I wanted, except for one thing: I didn’t know how to make conditional statements. I’m not even sure if they were, but I didn’t know how to get them to work with Movable Type’s tags.

The problem with a lack of understanding the tag system gives me this:

Before the change


While I never want to be accused of being a ‘grammar Nazi,’ it bugs me that I have ‘1 posts’ in some of the smaller archives. This bug shows up until I post the second post every month, and I’ve been too shiftless to find a solution. Luckily, one day as I was derelict in my slacking, I found the solution in the Movable Type Documentation.

Inserting this small snippet of code gave me the result I wanted:

<mt:If tag="ArchiveCount" gt="1">s</mt:if>

Now you can see that single post months have the requisite singular form, while months with multiple posts have the plural. And now I can go back to being a grammar Nazi.

After the change


I’m sure I missed this before, but it’s really helpful to have conditional tags. In fact, what I did with that small statement only hints at the power you can wield inside the template tags. Just using the built—in tag structure, you could create most–popular, most–commented, or a host of other ideas. No plugins, just tags.

Tagged:
Mark this | View blog reactions

Leave a comment