Using Textpattern CMS `css` and `feed_link`


Textpattern CMS, my content management system weapon on choice, uses a tag system to make life easier on certain tasks. This series of posts relates to markup tags, a toolbox of useful things that affect what happens in the browser markup. For this article, I’m rolling out two tags:

  • css
  • feed_link

They’re both pretty straightforward to figure out, so if you’re reeling from getting your head around another Textpattern tag and need a break, you’re in the right place. Briefly, `css` controls the CSS file a page uses and anything inside a pair of `hide` tags is hidden from the page source. I’ll start with `css`, then move onto `hide`. There’ll be examples, and it’ll be fun – I promise.

The `css` tag has five attributes to play around with, with sensible defaults – one of Textpattern’s trademarks:

  • format=”link or url” (build a full HTML link or just use the URL – default: `url`)
  • media=”value” (HTML `media` attribute when used `format=”link”` – default: `screen`)
  • name=”style name” (the stylesheet name – default: as set in Textpattern preferences)
  • rel=”value” (HTML `rel` attribute when used `format=”link”` – default: `stylesheet`)
  • title=”value” (HTML `title` attribute when used `format=”link”` – default: unset)

In the Hive theme, the default choice for new installations, the `css` tag is called like this:

<txp:css format="link" media="" />

Note there is no `name` attribute included. Each Textpattern section has a page and a style associated with it. The page builds the markup scaffolding, and the style provides the paint job. The `media` attribute value is removed and the result of this in the page markup is:

<link rel="stylesheet" href="">

The `css.php?n=default` part fetches the `default` style sheet from the database, and uses that for styling the page. This raises an important point: the style sheet is, by default, stored in the database and whenever `css` is used it will make a database call to retrieve said sheet. Using external style sheets – that is, having static files instead of a database table – will typically reduce the load time on your page, and also lower the number of database queries. If your server has a particularly busy MySQL instance, you may benefit from this route. You will lose the ability to edit stylesheets from the administration panel, but if you’re comfortable editing with an external editor that may be preferable.

In a similar vein, the `feed_link` tag builds a valid link to an RSS or Atom feed, depending on the values of its handful of attributes (with defaults in):

  • category=”category name” (default: current)
  • flavor=”rss or atom” (default: rss)
  • format=”a or link” (build an HTML link or anchor – default: a[nchor])
  • limit=”integer” (limit to this many articles – default: per Textpattern preferences)
  • section=”section name” (default: current)
  • title=”value” (HTML title attribute – default: depends upon `flavor`)

The default template uses an instance of both to create links to the respective feed flavours:

<txp:feed_link flavor="atom" format="link" label="Atom" />
<txp:feed_link flavor="rss" format="link" label="RSS" />

Which end up looking like this in the rendered code (messy URL mode):

<link rel="alternate" type="application/atom+xml" title="Atom feed" href="">
<link rel="alternate" type="application/rss+xml" title="RSS feed" href="">

Feed readers will happily work with the absolute URL provided for each flavour, or be able to figure it out if they’re just pointed at the page.

Next time: `hide`. Come back and find out more, it’ll be swell.

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, Uncategorized | 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 - - 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 *