Created
February 28, 2012 10:47
-
-
Save davidpmccormick/1931849 to your computer and use it in GitHub Desktop.
displays the previous twelve months in a list, formatted as words, with links in the form, '2012-01' for year and month, in order to be filtered for an archive view
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<xsl:template name="months"> <!-- display a list of linked month numbers (from 12 to 00) counting back from current month for archive pages --> | |
<xsl:param name="thismonth" select="$this-month"/> <!-- month number --> | |
<xsl:param name="countmonths" select="12"/> <!-- months in a year --> | |
<xsl:if test="$countmonths > 0"> | |
<xsl:choose> | |
<xsl:when test="$thismonth > 0"> <!-- if it's bigger than 0 --> | |
<xsl:choose> | |
<xsl:when test="string-length($thismonth) = 1"> <!-- if there's no preceding zero --> | |
<a href="{$root}/blog/archive/{$this-year}-0{$thismonth}"> | |
<li class="month-0{$thismonth}"> | |
<xsl:call-template name="format-date"> | |
<xsl:with-param name="date"><xsl:value-of select="$this-year"/>-0<xsl:value-of select="$thismonth"/>-01</xsl:with-param> <!-- add '01' to the end (the 'day') to allow the format-date function to parse it --> | |
<xsl:with-param name="format" select="'M'"/> | |
</xsl:call-template> | |
</li> | |
</a> <!-- prepend a zero --> | |
</xsl:when> | |
<xsl:otherwise> | |
<a href="{$root}/blog/archive/{$this-year}-{$thismonth}"> | |
<li class="month-{$thismonth}"> | |
<xsl:call-template name="format-date"> | |
<xsl:with-param name="date"><xsl:value-of select="$this-year"/>-<xsl:value-of select="$thismonth"/>-01</xsl:with-param> | |
<xsl:with-param name="format" select="'M'"/> | |
</xsl:call-template> | |
</li> | |
</a> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:when> | |
<xsl:otherwise> <!-- if it's smaller than 0 --> | |
<xsl:choose> | |
<xsl:when test="string-length($thismonth + 12) = 1"> <!-- if there's no preceding zero --> | |
<a href="{$root}/blog/archive/{$this-year - 1}-0{$thismonth + 12}"> | |
<li class="month-0{$thismonth + 12}"> | |
<xsl:call-template name="format-date"> | |
<xsl:with-param name="date"><xsl:value-of select="$this-year - 1"/>-0<xsl:value-of select="$thismonth + 12"/>-01</xsl:with-param> | |
<xsl:with-param name="format" select="'M'"/> | |
</xsl:call-template> | |
</li> <!-- prepend a zero and add 12 --> | |
</a> | |
</xsl:when> | |
<xsl:otherwise> | |
<a href="{$root}/blog/archive/{$this-year - 1}-{$thismonth + 12}"> | |
<li class="month-{$thismonth + 12}"> | |
<xsl:call-template name="format-date"> | |
<xsl:with-param name="date"><xsl:value-of select="$this-year - 1"/>-<xsl:value-of select="$thismonth + 12"/>-01</xsl:with-param> | |
<xsl:with-param name="format" select="'M'"/> | |
</xsl:call-template> | |
</li> | |
</a> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:otherwise> | |
</xsl:choose> | |
<xsl:call-template name="months"> | |
<xsl:with-param name="thismonth" select="$thismonth - 1"/> | |
<xsl:with-param name="countmonths" select="$countmonths - 1"/> | |
</xsl:call-template> | |
</xsl:if> | |
</xsl:template> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment