Understanding Textpattern CMS `link_to_home`, `link_to_next` and `link_to_prev` tags

admin-ajaxPart three of my five part series on Textpattern CMS navigational tags focuses on three intriguing tags that, frankly, I don’t use as often as I should. There’s a scene in the movie Léon where the hitman visits his handler to collect a weapon for training purposes. That’s my reason for wheeling these three tags out today; you’ll learn something new, and I’ll refresh my skills. These are the tags in question:

  • `link_to_home`
  • `link_to_next`
  • `link_to_prev`

The `link_to_home` is a curious one in that it can be used as single or container tag, but is far more useful as a container. With its single attribute (css=”CSS class name”), there’s not much in the way of customisation available within the tag itself. Using `link_to_home` in its single container guise outputs a hyperlinked URL to the Textpattern site:

<txp:link_to_home />

This is almost the same as using `site_url` without the hyperlinked stuff, though it can be built-on to achieve the same thing. This code is more verbose, but does the same thing as `link_to_home`:

<a href="<txp:site_url />"><txp:site_url /></a>

The other two tags, `link_to_next` and `link_to_prev`, are also in the One Attribute Textpattern Tag Club (it’s a thing that I’m starting this year). These tags are used to navigate between individual articles: `link_to_next` generates the URL for the next article in the list, and `link_to_prev` does the same thing for the previous article. Now you know what the tags do, the sole attribute is `showalways` (boolean value, defaults to 0) and is more readily understood: the most recent article won’t ever have a newer article to link to, by definition. The same goes for the oldest article – there is nothing older than oldest (that got deep and meaningful, woah).

In these instances, using a vanilla `link_to_next` or `link_to_prev` respectively will do nothing – it will be ignored. However, when `link_to_next` and `link_to_prev` are used with `showalways=”1″`, they will always be processed. This can lead to some confusing user interface elements, so be absolutely sure you know what you’re doing if you roll this out.

Although `link_to_next` and `link_to_prev` are basic in their use (i.e., they spit out a URL), they can be wrapped in extra things to make them more useful. For example:

<txp:link_to_prev><txp:prev_title /></txp:link_to_prev>

This is `link_to_prev` being used as a container/wrapper, and the innards are generated by the `prev-title` tag. This generates a hyperlinked article title, and in the context of an article form, it’s dynamic to each article. The gotcha you need to be careful of with both of these tags is demonstrated in the following example:

<txp:link_to_next showalways="1"><txp:next_title /></txp:link_to_next>

Where the article is the newest (i.e., most recent), `next_title` won’t return anything, so nothing will be shown to the visitor. Likewise, the `link_to_next` doesn’t have anything to extract a URL from, so won’t generate anything. In the years I’ve been using and deploying Textpattern, I haven’t ever had an occasion to use `showalways`, and should that situation arise I will be very happy to share feedback with you.

Looking for quality Textpattern Hosting? Look no further than Arvixe Web Hosting and use coupon TEXTPATTERN for 20% off your first invoice!

Tags: , , , , , , , , , | Posted under Textpattern | RSS 2.0

Author Spotlight

Pete Cooper

Pete Cooper has been using Textpattern since 2005. Textpattern is his preferred CMS weapon of choice. Its logical and flexible approach to content management makes Pete happy, as does its lightweight core and helpful user community. Pete's website - petecooper.org - runs on top of Textpattern and chronicles his day-to-day experiences from his home near the Atlantic in north Cornwall, United Kingdom.

Leave a Reply

Your email address will not be published. Required fields are marked *