This is part four of my five part series on Textpattern CMS navigational tags. I’m going to follow the format of the previous posts and explain about a couple of Textpattern tags, their attributes and typical usage. Getting to grips with tags will make your Textpattern experience more fulfilling and perhaps even a heck of a lot easier when you grasp the fundamentals of how they work. In this article, I’m going to cover two tags:
Both of these tags have been designed and implemented so that they can be wheeled out as single or container tags, which makes them particularly helpful when your Textpattern sites increase in complexity and scope.
The `newer` and `older` tags share the same three attributes:
- escape=”html or unset” (default: html)
- showalways=”boolean” (default: 0, unset)
- title=”HTML title attribute” (default: unset)
In an earlier post, I explained how you should be careful when using `showalways`. With the `newer` and `older` tags, if there’re no newer or older articles to show, nothing will be displayed. This can lead to confusing UI problems, so avoid it where possible.
The usage examples are functional rather than exciting. Here’s how to make an image into a hyperlink to the older article in the list:
<a href="<txp:older />"><img src="older.png" id="older-image" /></a>
That’s the single tag at work: it builds the plain URL and the other stuff wrapped around it switches it to a hyperlink. Want to see a container example? Certainly:
Jumping back to the `showalways` attribute and the concept of a check for whether newer or older articles exist in a list, the structure of the `newer` and `older` tags is important. Consider these two examples:
<a href="<txp:older />"><img src="older.png" id="older-image" /></a> <txp:older><img src="older.png" id="older-image" /></txp:older>
In the first of the two, the image will be displayed whether there are older articles or not (read: confusing UI), whereas the second will do a sanity check first – if there’s no older articles, the image will not be displayed. Clever stuff.
And, well, that’s about it. Experiment with what works best for your site, but be aware of the `showalways` pitfalls.
Next time: `section` and `section_list`.