In my previous article, I demonstrated how Textpattern CMS handles the generation of article links in both the <head> and <body> section of the page using the <txp:feed_link> tag. It’s possible to extend this functionality further with appropriate use of attributes within the same tag. As I write this, the current version of Textpattern recognizes the following attributes in the <txp:feed_link> tag:
- category – restrict articles a specified category
- flavor – output a link to the RSS or Atom version of the feed
- format – output an anchor tag or link tag
- limit – how many articles are in the feed
- section – restrict articles to a specific section
- title – the HTML title attribute
You may recognize some of them from the tag constructs I used in the last article, most should be new to you. Textpattern logic assumes that each of the above attributes has a default, and in the case of <txp:feed_link> all the attributes are optional. The defaults are:
- category – current category
- flavor – RSS
- format – anchor
- limit – depends upon administration preference setting.
- section – current section.
- title – depends on flavor, either RSS feed or Atom feed
This tag construct uses the defaults builds a link accordingly:
Overriding the defaults is easy enough, just tack on some attributes. For example, if you have a section where it’s important to have more articles syndicated (say, 50) than your other sections (which are set to 10), using this tag construct will give you what you want:
<txp:feed_link limit="50" />
Equally, if this section should be available as a link throughout the site, you can force the section name into the construct, like this:
<txp:feed_link limit="50" section="fruit" />
Perhaps you have two specific sections that you wish to merge into one feed:
<txp:feed_link limit="50" section="fruit,vegetable" />
Clever, huh? How about switching it to Atom instead of RSS? Easy:
<txp:feed_link flavor="atom" limit="50" section="fruit,vegetable" />
Any or all of the attributes can be used. Note that this tag construct is self-closing; there’s a trailing slash before the >. The <txp:feed_link> can also be used as a container tag and wrapped around an image, for example:
<txp:feed_link flavor="atom" limit="50" section="fruit,vegetable"><img src=atom.png /></txp:feed_link />
Or, you can get really neat with a tag inside a tag:
<txp:feed_link flavor="atom" limit="50" section="fruit,vegetable"><txp:image id="1" /></txp:feed_link />
…which turns the Textpattern image with ID reference number 1 into a hyperlink.
There’s a plenty more to learn about the <txp:feed_link> tag, take a look at the Textpattern documentation wiki for more examples and explanations. Next time, I’ll show you how to automatically post your Textpattern articles to Twitter with Twitterfeed.