The goal is to create a paginated alphabetic articles list, as requested here.
- Pagination · 2012-09-13
- peg_nested_comments · 2012-10-31
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)
- File: etc_query.txt [60.72 kB] (4246 downloads, ~29 per month)
- File: etc_pagination.txt [43.19 kB] (1965 downloads, ~14 per month)