Tuesday 11 November 2008 by

As almost nothing is made to last forever, articles may carry an expiry date/time in the upcoming Textpattern 4.0.7 release.

Various hacks and plugins have catered for this requirement in the past, with each of those having their own issues: They’d either hide articles in webfeeds up to the expiry date or on the contrary publish expired articles through feeds even past the expiry date, or mangle the article’s data itself.

With Textpattern 4.0.7, an additional timestamp designates an article’s expected shelf life:

Setting an article’s expiry date in Textpattern 4.0.7

Related tags

A few new template tags will complement this feature:

  • <txp:expires /> mimicks the behaviour and attribute set of <txp:posted />
  • <txp:if_expires>...<txp:else />...</txp:if_expires>: Checks for the mere presence of an expiry date.
  • <txp:if_expired>...<txp:else />...</txp:if_expired>: Checks if the current article is past its expiry date.

Preferences

One additional preference setting dubbed “Publish expired articles” changes the way how Textpattern handles expired articles.

If set to “Yes”, articles will stay visible to the public even after their expiry time has elapsed. At first glance, this might look a bit nonsensical, but this is where <txp:if_expired> has its chance to chime in and render a slice of conditional markup for past gigs, training courses, announcements, whatever – without ripping out precious pages from the search engines’ indexes.

Setting “Publish expired articles” to “No” results in a snippy ‘410 Gone’ response when an expired article is requested. As for all of Textpattern’s 4xx responses, you can craft a page template named ‘error_410’ to customize the looks of that response page.