Textpattern has a nifty little feature which allows one to set an expiration date on an article. Very nice for sites which have time-sensitive material.
However, it can take a little tweaking to get the output on your site just the way you want it. Following are a couple of methods you can try for yourself.
Example 1: Display articles which have expired
<txp:variable name="hasarticles" value='<txp:article_custom section="your-section" expired="1" />' />
<txp:if_variable name="hasarticles" value="">
<div class="row">
<div class="small-12 columns">
<div class="panel">
<p>Sorry! we don't have any expired articles!</p>
</div>
</div>
</div>
<txp:else />
<txp:article>
<div class="row">
<div class="small-12 columns">
<txp:if_expired>
<h2><txp:title /></h2>
<p>Some expired article description...</p>
<txp:else />
<h2><txp:permlink><txp:title /></txp:permlink></h2>
<p><txp:excerpt /></p>
</txp:if_expired>
</div>
</div>
</txp:article>
</txp:if_variable>
What the above code does is:
- Set a variable to the value of
<txp:article_custom section="your-section" expired="1" />
- The attribute
expired="1"
selects only articles which have expired - Display a message if there are no expired articles
- If there are expired articles, then use the txp:if_expired> tag to display some custom content
Example 2: Display articles which have NOT expired
<txp:variable name="hasarticles" value='<txp:article_custom section="your-section" expired="0" />' />
<txp:if_variable name="hasarticles" value="">
<div class="row">
<div class="small-12 columns">
<div class="panel">
<p>Sorry! we don't have anything to show you.</p>
</div>
</div>
</div>
<txp:else />
<txp:article>
<div class="row">
<div class="small-12 columns">
<txp:if_expired>
<txp:else />
<h2><txp:permlink><txp:title /></txp:permlink></h2>
<p><txp:excerpt /></p>
</txp:if_expired>
</div>
</div>
</txp:article>
</txp:if_variable>
What the above code does is:
- Set a variable to the value of
<txp:article_custom section="your-section" expired="0" />
- The attribute
expired="0"
selects only articles which have NOT expired - Display a message if there are no articles retrieved in the query
- Display some custom content for the non-expired articles
Don’t forget your expired articles preference…
By default, Textpattern does not publish expired articles. That means if an article you published a long time ago with a URL is clicked by a visitor, Textpattern will display a 410 error notice
.
From the Publish expired articles
help page:
Preferences: Publish expired articles?
When set to ‘Yes’, expired articles will continue to show on your site after their expiry date has elapsed. You can use <txp:if_expired /> to show alternate content or markup for expired articles.
When set to ‘No’, expired articles will be removed from the public site and return a “410 Gone” HTTP status instead. Visitors to an expired article will be shown a custom page template named ‘error_410’ if it’s present.
The default setting is ‘No’.
Play around with the settings and above code examples and hopefully you will get close to your desired result!