Sortable TXP archive

Update: The code has changed to be more streamlined, thanks to the helpful people on the Textpattern Forum. This tweak allows for category names to be displayed, previously thought to not be possible in the case of link lists.

Before we begin: This article is not about Ajax. Thanks. I have seen quite a few people tagging various CSS tutorials I've done as Ajax on, most of which did not even involve JavaScript. So, I wanted to state that up front, lest there be any confusion, since this one involves a bit of JS. However, our friend XMLHttpRequest was not invited to the party this time around. This article also presupposes a certain degree of familiarity with Textpattern.

If you visited my site lately, you might have noticed that I overhauled my Journal Archive section. I've had a few enquiries about how I set up the template logic in Textpattern, so I figured I should probably write up a little tutorial. I am quite pleased with how it turned out, and the fact no plugins were required. Previously, I was using the Super Archive by Rob Sable.

So, first off I'll provide *.txt versions of the TXP code used in the various parts of the archive, so that it won't get parsed and turned into HTML in this very article. There are three main things involved: The Archive page template, the TXP form for the posts, and the TXP forms for categories.

Hopefully that code will make sense. There is conditional logic to determine which of the archives is being displayed: posts or links. There is also conditional logic to check if there are comments. If so, the first one is linked to. If not, then there is simply the number 0 with no link provided. Likewise, if the 6 week feedback period has expired, the discussion is shown as Closed. If it is still open, it is listed as Active, with a link to the comment form itself.

Also take note of the classes on each of the th column headers. You must specify sortable for each one you want to be dynamic. The only one that is special is the Comments column, with a class name of sortable-numeric, so that numbers like 9 won't come after 83 when the user sorts by comments. For more on how it works, check out the original article by Brian McAllister.