Texpattern context demo

Current global context
SectionDate
context_demo2008

Date-based archives

As I wrote in Date context, article is the only date-sensitive tag in Txp:

This code:

<txp:article sort="Posted" limit="3" wraptag="ul" break="li">
	<txp:permlink><txp:title /></txp:permlink> (<txp:posted />)
</txp:article>

produces this output:

If you picked a context earlier than 2011, the above list is empty, because this section has no articles older than that (the example menu in Date context was based on article_custom and so included articles from all sections of this site). article_custom can select articles by date, using the same date format as month, so here’s a way to fake context-sensitive behavior:

This code:

<txp:article_custom sort="Posted" limit="5" wraptag="ul" break="li" 
	month='<txp:page_url type="month" />'>
		<txp:permlink><txp:title /></txp:permlink> (<txp:posted />)
</txp:article_custom>

produces this output:

The extensive use of if_different is for nesting the HTML tags properly, and for not repeating dates.

Finally, just for fun, here’s a date-based article archive formatted as a nested definition list. Used as shown it is date-context-sensitive; used without the month attribute in the article_custom tag it would show a full site archive (as you can see for yourself by putting a month value of 2 or 20 into the URL).

This code:

<txp:article_custom sort="Posted" limit="9999" wraptag="dl" break="" class="archive"
 month='<txp:page_url type="month" />'>
	<txp:variable name="close_tags" value=
		'<txp:if_different></dl></dd><txp:posted format="<!--%Y%m-->" /></txp:if_different>' />
	<txp:if_first_article><txp:else /><txp:variable name="close_tags" /></txp:if_first_article>
	<txp:if_different><dt class="year"><txp:posted format="%Y" /></dt></txp:if_different>
	<txp:if_different><dd><b><txp:posted format="<!--%Y-->%b" /></b><dl></txp:if_different>
		<txp:if_different><dt><txp:posted format="<!--%F-->%d" /></dt></txp:if_different>
		<dd><txp:permlink><txp:title /></txp:permlink></dd>
	<txp:if_last_article></dl></dd></txp:if_last_article>
</txp:article_custom>

produces this output:

2008
Jan
28
soo_toc
30
Static CSS with Textpattern
Check HTML syntax in BBEdit (first version)
Applescript for W3C validator
31
Colophon
Feb
02
Check HTML syntax in BBEdit (revised)