How to build an grouped archive in Textpattern

You can build an archive of blog posts/articles which is grouped by year and months with built in tags. The nested tags and HTML elements are looking really weird but it works as unordered nested list.

<txp:article_custom sort="Posted desc" limit="99999" wraptag="ul" break="" class="archive">

	<txp:variable name="year" value='<txp:if_different><txp:posted format="%Y" /></txp:if_different>' />
	<txp:variable name="month" value='<txp:if_different><txp:posted format="%B" /></txp:if_different>' />

	<txp:if_variable name="year" value=""><txp:else />
		<txp:if_first_article><txp:else />
					</ul>
				</li>
			</ul>
		</txp:if_first_article>
		<li><h2><txp:posted format="%Y" /></h2>
			<ul>
	</txp:variable>

	<txp:if_variable name="month" value=""><txp:else />
		<txp:if_variable name="year" value="">
				</ul>
			</li>
		<txp:else /></txp:if_variable>
		<li><h3><txp:posted format="%B" /></h3>
			<ul>
	</txp:variable>

	<li><txp:posted />: <txp:permlink><txp:title /></txp:permlink></li>

	<txp:if_last_article></ul></li></ul></txp:if_last_article>

</txp:article_custom>

Kommentar

  1. # - TNT schrieb am 29. Februar 2012, 14:22:

    Hooray!!

    Just what I was looking for for a project. I couldn’t get my head around it – those <txp:variables /> are still a bit of mystery for me.

    Thank you!

  2. # - trenc schrieb am 1. März 2012, 11:35:

    You're welcome!

    Think of the <txp:variable /> as an empty container, which can hold what you put into. I used the <txp:variable /> in the example above as workaround for a <txp:if_different /> but without any output when true (normally it has an output when true and none when false).





Textile-Hilfe