Yearly posts calendar

2015-09-30 11:37

Keywords: archive, calendar

From the Forum:

Can I have a menu which looks like a calender and where I can choose years of months for which I can see the posts of that month?

If you don’t need much bells and whistles, here is the yearly posts solution.

<!-- grids construction -->
<txp:etc_query name="grid" data="[2012..{?|now|date(Y)}]">
<thead><tr><th colspan="4">{?}</th></tr></thead>
	<td id="month-{?}-01">Jan</td>
	<td id="month-{?}-02">Feb</td>
	<td id="month-{?}-03">Mar</td>
	<td id="month-{?}-04">Apr</td>
	<td id="month-{?}-05">May</td>
	<td id="month-{?}-06">Jun</td>
	<td id="month-{?}-07">Jul</td>
	<td id="month-{?}-08">Aug</td>
	<td id="month-{?}-09">Sep</td>
	<td id="month-{?}-10">Oct</td>
	<td id="month-{?}-11">Nov</td>
	<td id="month-{?}-12">Dec</td>

<!-- retrieve posts counts and prepare replacements -->
<txp:etc_query name="replace" break=";"
	data="SELECT COUNT(*) cnt, YEAR(Posted) year, DATE_FORMAT(Posted, '%m') month FROM textpattern WHERE Status=4 GROUP BY DATE_FORMAT(Posted, '%Y-%m') ORDER BY Posted">
	id('month-{year?}-{month?}')@@.=<a href='?month={year?}-{month?}'>{{node()}}<br /><span>{cnt?} {$(cnt?).=1.?(Post|Posts)}</span></a>@class=busy

<!-- fill the grid -->
<txp:etc_query data='<txp:variable name="grid" />' replace='<txp:variable name="replace" />' />

Your calendar is ready now, with linked posts counts and busy class added to “productive” months cells. Add a bit of style to customize the result ad infinitum.

Monthly calendars are feasible too, but trickier, so I leave it with you.