Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Hacking pagination with article_custom
I’m trying to figure out the best way to enable pagination with article_custom article lists. I can share what I have so far, which I think is a solid foundation, but I’m hitting a road block with actually generating page links that will work in every context. The plugins I’m using are adi_gps, adi_calc, and rah_repeat, as follows:
- Add
<txp:adi_gps name="page" quiet="1" />
- Add
<txp:variable name="article-count" value="0" />
- Add
<txp:variable name="article-limit" value="10" />
or however many you want - Duplicate the article_custom tag that you are trying to paginate, but set
limit="9999"
and make it a container tag with just<txp:adi_calc name"article-count" add="1" />
in it. - After that article_custom tag, add:
<txp:adi_calc name="page-count" value='<txp:variable name="article-count" />' div='<txp:variable name="article-limit" />' />
. This both creates the variable “page-count” and makes it the correct value in a single tag, using some simple math and the other existing variables. - In the article_custom tag that you want to paginate, set
limit='<txp:variable name="article-limit" />'
andoffset='<txp:if_variable name="page" value="">0<txp:else /><txp:adi_calc name="page" subtract="1" /><txp:adi_calc name="page" multiply='<txp:variable name="article-limit" />' display="1" /></txp:if_variable>'
- Make your page links (warning – this part doesn’t really work correctly):
<txp:rah_repeat limit='<txp:variable name="page-count" />' value="1,2,3,4,5,6,7,8,9,10,11,12,13,14,15" >
<a href='<txp:page_url type="request_uri" />&page=<txp:rah_repeat_value />'><txp:rah_repeat_value /></a>
</txp:rah_repeat>
That last part is where I’m getting stuck. As an aside, rah_repeat seems to require entering a bunch of values in the value attribute, greater than or equal to it’s limit attribute, in order for it to repeat anything. Otherwise, I would probably just use another variable and adi_calc to increment the page links, in place of rah_repeat_value
.
Unfortunately, the method above basically just always appends &page=n
to the current url. That works the first time you change pages, but subsequently you end up with &page=n&page=m&page=o
in the url. I know that an html select form can update a url variable correctly, so I can use this:
<form action='<txp:page_url type="request_uri" />' method="get">
<select class="selector" name="page" onChange="this.form.submit();">
<txp:rah_repeat limit='<txp:variable name="page-count" />' value="1,2,3,4,5,6,7,8,9,10,11,12,13,14,15" >
<option value='<txp:rah_repeat_value />'><txp:rah_repeat_value /></option>
</txp:rah_repeat>
</select>
<noscript><input type="submit" value="Go!"></noscript>
</form>
…but what I really need is a “Google-style” page link list instead of a select form.
Thanks for reading this long post, and if you can comprehend what is going on above and see a good solution to generating the page links, I would greatly appreciate any input you might have.
Offline
Re: Hacking pagination with article_custom
aswihart wrote:
That works the first time you change pages, but subsequently you end up with &page=n&page=m&page=o in the url.
You could, for instance, use TXP’s tags to generate fitting URLs. For example:
<a href="?s=<txp:section />&c=<txp:category />&page=<txp:rah_repeat_value />">
<txp:rah_repeat_value />
</a>
Last edited by Gocom (2010-05-18 04:31:47)
Offline
Re: Hacking pagination with article_custom
Thanks Jukka, I think my brain stopped working for some reason, I should have thought of that. I actually need to add several url variables to the link as well, but I think I can do that easily with adi_gps.
As a side note, what do people think of this article_custom pagination solution? Is this pretty much standard stuff that everyone is using, or does someone have a different / better method?
Offline
#4 2010-05-19 13:03:37
- ax
- Plugin Author
- From: Germany
- Registered: 2009-08-19
- Posts: 165
Re: Hacking pagination with article_custom
As a side note, what do people think of this article_custom pagination solution? Is this pretty much standard stuff that everyone is using, or does someone have a different / better method?
Since pagination for article_custom is not in the textpattern core (yet),and it seems that there is no other / better method, it certainly would be useful for many of us if you could summarize your method as a tutorial in the Textpattern wiki.
Last edited by ax (2010-05-19 13:07:45)
Offline
Re: Hacking pagination with article_custom
Better still, submit it as a TXP Tip for everyones benefit. Or email me directly…
Offline
Re: Hacking pagination with article_custom
Thanks guys, I plan on adding it to Txp Tips, I just wanted to see if there were any other / better ideas out there. I guess this is pretty good as it is. I do need to change the method for calculating the page-count, because adi_calc doesn’t currently allow rounding up to the next whole number after division operations. I will email you with a final tutorial sometime soon Jonathan.
Offline
Re: Hacking pagination with article_custom
Thanks Andrew. I think the best thing about TXP Tips is that it features many ways to achieve the same goal – and your method (sorry have not read what it is yet) is bound to be interesting to many people.
Offline