Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Re: Complex Pagination using Newer/Older with Shift
philwareham wrote #323392:
Note to self: we should write a blog article for this once Textpattern 4.8.1 ships – detailing Michael’s original code and the other updates from all here. Very handy!
Maybe I can ask Michael to incorporate these in a new article for txptips?
TXP Builders – finely-crafted code, design and txp
Offline
Re: Complex Pagination using Newer/Older with Shift
jakob wrote #323394:
Maybe I can ask Michael to incorporate these in a new article for txptips?
OK, sure – that makes sense. Basically as long as the solution is detailed somewhere that’s helpful for future reference (things in the forum get a bit buried after a few months, naturally).
Offline
Re: Complex Pagination using Newer/Older with Shift
Slightly OT but I was thinking of starting a series of short blog articles on .com prefixed with Feature focus:. I penned one yesterday (currently draft) on pageless sections and a little mention of the multi-edit tool’s ability to set them.
If anybody would like to write or propose an article for this series that focuses on a particular aspect of 4.8.x then please drop it to one of us. It could go hand-in-hand with a txptip.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Hire Txp Builders – finely-crafted code, design and Txp
Offline
Re: Complex Pagination using Newer/Older with Shift
jakob wrote #323394:
Maybe I can ask Michael to incorporate these in a new article for txptips?
I will try to whip something up this weekend. I’ve been following the discussion.
Offline
Re: Complex Pagination using Newer/Older with Shift
Hi, just reviving this old thread with a new question.
OK, so I had this pagination code working fine on a few sites:
<txp:pages pg link="" showalways="2" evaluate="5,2,8,4,6">
<nav class="paginator" aria-label="Page navigation">
<txp:newer showalways><a rel="prev" href="<txp:yield item="url" />">Previous</a></txp:newer>
<ul class="pagination">
<txp:newer shift><li><a href="<txp:yield item="url" />"><txp:yield item="page" /></a></li></txp:newer>
<txp:newer shift="-2"><li role="separator" aria-label="More pages">…</li></txp:newer>
<txp:newer total shift="2"><li><a href="<txp:yield item="url" />"><txp:yield item="page" /></a></li></txp:newer>
<txp:pages><li class="current"><b title="Current page" aria-current="page"><txp:yield item="page" /></b></li></txp:pages>
<txp:older total shift="2"><li><a href="<txp:yield item="url" />"><txp:yield item="page" /></a></li></txp:older>
<txp:older shift="-2"><li role="separator" aria-label="More pages">…</li></txp:older>
<txp:older shift><li><a href="<txp:yield item="url" />"><txp:yield item="page" /></a></li></txp:older>
</ul>
<txp:older showalways><a rel="next" href="<txp:yield item="url" />">Next</a></txp:older>
</nav>
</txp:pages>
But now I want to use that for a theme I’m creating for Textpattern, so I’d changed the various hardcoded texts in the above with actual <txp:text /> tags for multilingual use. Like so:
<txp:pages pg link="" showalways="2" evaluate="5,2,8,4,6">
<nav class="paginator" aria-label="<txp:text item="page_nav" />">
<txp:newer showalways><a rel="prev" href="<txp:yield item="url" />"><txp:text item="prev" /></a></txp:newer>
<ul class="pagination">
<txp:newer shift><li><a href="<txp:yield item="url" />"><txp:yield item="page" /></a></li></txp:newer>
<txp:newer shift="-2"><li role="separator" aria-label="<txp:text item="more_pages" />">…</li></txp:newer>
<txp:newer total shift="2"><li><a href="<txp:yield item="url" />"><txp:yield item="page" /></a></li></txp:newer>
<txp:pages><li class="current"><b aria-current="page"><txp:yield item="page" /></b></li></txp:pages>
<txp:older total shift="2"><li><a href="<txp:yield item="url" />"><txp:yield item="page" /></a></li></txp:older>
<txp:older shift="-2"><li role="separator" aria-label="<txp:text item="more_pages" />">…</li></txp:older>
<txp:older shift><li><a href="<txp:yield item="url" />"><txp:yield item="page" /></a></li></txp:older>
</ul>
<txp:older showalways><a rel="next" href="<txp:yield item="url" />"><txp:text item="next" /></a></txp:older>
</nav>
</txp:pages>
And now the pagination code is pretty broken. I think it may be to do with the evaluate attribute and maybe it’s evaluating the text tags as well – but I’m not clever enough to work out how the evaluation works here anyway (I used Oleg’s code examples to make the pagination in the first place, and I admit I don’t really know how the nuts and bolts of this work).
Any suggestions on how to fix greatly appreciated.
Offline
Re: Complex Pagination using Newer/Older with Shift
The numbers in evaluate are the ‘positions’ of the tags inside the container that you want to evaluate, in the order you want them to be executed. In the original, the 5th top-level child <txp: tag (the <txp:pages> in the middle) was executed first. Then the 2nd (the first <txp:newer> inside the <ul>) and so forth.
When you introduced <txp:text> above those in the outer <nav>, you’ve pushed all the numerical indexes down by one. The other <txp:text> tags are all attributes inside other tags, so don’t count in the indexing, because they’re not direct descendants (first-child) tags of the tag that has the evaluate attribute.
I reckon if you add one to all the numbers in the evaluate tag, it’ll work again.
Last edited by Bloke (2020-10-13 08:30:22)
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Hire Txp Builders – finely-crafted code, design and Txp
Offline
Re: Complex Pagination using Newer/Older with Shift
Ah, OK thanks – well that was easy (it’s fixed now).
For reference this is the working code:
<txp:pages pg link="" showalways="2" evaluate="6,3,9,5,7">
<nav class="paginator" aria-label="<txp:text item="page_nav" />">
<txp:newer showalways><a rel="prev" href="<txp:yield item="url" />"><txp:text item="prev" /></a></txp:newer>
<ul class="pagination">
<txp:newer shift><li><a href="<txp:yield item="url" />"><txp:yield item="page" /></a></li></txp:newer>
<txp:newer shift="-2"><li role="separator" aria-label="<txp:text item="more_pages" />">…</li></txp:newer>
<txp:newer total shift="2"><li><a href="<txp:yield item="url" />"><txp:yield item="page" /></a></li></txp:newer>
<txp:pages><li class="current"><b aria-current="page"><txp:yield item="page" /></b></li></txp:pages>
<txp:older total shift="2"><li><a href="<txp:yield item="url" />"><txp:yield item="page" /></a></li></txp:older>
<txp:older shift="-2"><li role="separator" aria-label="<txp:text item="more_pages" />">…</li></txp:older>
<txp:older shift><li><a href="<txp:yield item="url" />"><txp:yield item="page" /></a></li></txp:older>
</ul>
<txp:older showalways><a rel="next" href="<txp:yield item="url" />"><txp:text item="next" /></a></txp:older>
</nav>
</txp:pages>
Offline
Re: Complex Pagination using Newer/Older with Shift
Bloke wrote #326347:
When you introduced
<txp:text>above those in the outer<nav>, you’ve pushed all the numerical indexes down by one.
Would introducing some ignore attribute be handy? Generally, tags like <txp:text /> output something, so testing them for emptiness is useless.
Edit: though, for positional tags this could be confusing.
Offline
Re: Complex Pagination using Newer/Older with Shift
etc wrote #326369:
Would introducing some
ignoreattribute be handy? Generally, tags like<txp:text />output something, so testing them for emptiness is useless.
Seems like a good idea.
Offline
Offline
Re: Complex Pagination using Newer/Older with Shift
etc wrote #326369:
Would introducing some
ignoreattribute be handy? Generally, tags like<txp:text />output something, so testing them for emptiness is useless.Edit: though, for positional tags this could be confusing.
Hmm… not dismissing this out of hand, but doesn’t this introduce yet another cognitive complexity on the end-users side ? (I mean, already phil got slightly lost in deciding what is been evaluated in the code above, I fear an ignore attribute may run into similar problems)
Where is that emoji for a solar powered submarine when you need it ?
Sand space – admin theme for Textpattern
phiw13 on Codeberg
Offline
Re: Complex Pagination using Newer/Older with Shift
phiw13 wrote #326372:
Hmm… not dismissing this out of hand, but doesn’t this introduce yet another cognitive complexity on the end-users side ?
It does. An easier (end-user wise) option might be some global order attribute that alters the order the tags are processed in inside each block. Code-wise it’s another story, though…
Offline
Re: Complex Pagination using Newer/Older with Shift
etc wrote #326374:
An easier (end-user wise) option might be some global
orderattribute that alters the order the tags are processed in inside each block.
Finally done, via a new <txp:tag[n] /> syntax, to be approved/chosen by the community:
<!-- copy the whole block -->
<txp:variable name="test" add output /> (outputs 6)
<txp:variable[2] name="test" output>5</txp:variable> (outputs 5)
<txp:variable[1] name="test" add output /> (outputs 1)
Offline
Re: Complex Pagination using Newer/Older with Shift
etc wrote #326433:
Finally done, via a new
<txp:tag[n] />syntax, to be approved/chosen by the community:
Which means Phil can set the tags processing priority independently of addition/deletion another tags:
<txp:pages pg link="" showalways="2">
<nav class="paginator" aria-label="<txp:text item="page_nav" />">
<txp:newer showalways><a rel="prev" href="<txp:yield item="url" />"><txp:text item="prev" /></a></txp:newer>
<ul class="pagination">
<txp:newer[2] shift><li><a href="<txp:yield item="url" />"><txp:yield item="page" /></a></li></txp:newer>
<txp:newer shift="-2"><li role="separator" aria-label="<txp:text item="more_pages" />">…</li></txp:newer>
<txp:newer[3] total shift="2"><li><a href="<txp:yield item="url" />"><txp:yield item="page" /></a></li></txp:newer>
<txp:pages[1]><li class="current"><b aria-current="page"><txp:yield item="page" /></b></li></txp:pages>
<txp:older[3] total shift="2"><li><a href="<txp:yield item="url" />"><txp:yield item="page" /></a></li></txp:older>
<txp:older shift="-2"><li role="separator" aria-label="<txp:text item="more_pages" />">…</li></txp:older>
<txp:older[2] shift><li><a href="<txp:yield item="url" />"><txp:yield item="page" /></a></li></txp:older>
</ul>
<txp:older showalways><a rel="next" href="<txp:yield item="url" />"><txp:text item="next" /></a></txp:older>
</nav>
</txp:pages>
Offline
Re: Complex Pagination using Newer/Older with Shift
Thanks Oleg – is this method less taxing on resources than using the evaluate method – or it is negligible difference?
Offline