Alphabetic list

9 November 2013

Keywords: paginate, catalog, dictionary

The goal is to create a paginated alphabetic articles list, as requested here.

Code

<!-- alpha list -->
<txp:etc_query wraptag="nav" break=" | " name="alphalist"
	data="SELECT DISTINCT UPPER(SUBSTRING(Title,1,1)) AS alpha FROM textpattern WHERE Status = 4 ORDER BY alpha"
>
	<a href="?alpha={alpha?}">{alpha?}</a>
</txp:etc_query>

<!-- output alphalist and get articles ids when necessary -->
<txp:etc_query globals="_GET" data='<txp:variable name="alphalist" />'
	query="//a[text() = '{?alpha|A}']"
	replace="&=<span class='active'>{?alpha|A}</span>"
>
	{//nav}
	<txp:etc_query name="ids" break=","
		data="SELECT ID FROM textpattern WHERE UPPER(SUBSTRING(Title,1,1)) = '{?alpha|A}' AND Status = 4 ORDER BY Title" />
<txp:else />
	<txp:variable name="alphalist" />
</txp:etc_query>

<txp:if_variable name="ids">
	<!-- Pagination bar -->
	<txp:etc_query name="pages" data="{?ids|1|substr_count($|,).+1./2.ceil}" />
	<txp:etc_pagination pgcounter="page" link="Page {*}" wraptag="nav" break=" | "
		pages='<txp:variable name="pages" />'  />
	<!-- articles output -->
	<txp:article_custom id='<txp:variable name="ids" />' limit="2"
		offset='<txp:etc_offset pgcounter="page" pageby="2" />' />
</txp:if_variable>

File(s)