Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#31 2020-05-29 08:19:05

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 3,946
Website

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

#32 2020-05-29 08:20:45

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,396
Website

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

#33 2020-05-29 08:28:17

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 9,792
Website

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.

Txp Builders – finely-crafted code, design and Txp

Offline

#34 2020-05-29 13:06:16

michaelkpate
Moderator
From: Avon Park, FL
Registered: 2004-02-24
Posts: 1,330
Website

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

#35 2020-10-13 08:16:25

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,396
Website

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

#36 2020-10-13 08:27:24

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 9,792
Website

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.

Txp Builders – finely-crafted code, design and Txp

Offline

#37 2020-10-13 08:46:26

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,396
Website

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

#38 2020-10-14 07:25:27

etc
Developer
Registered: 2010-11-11
Posts: 3,940
Website

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

#39 2020-10-14 07:27:43

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,396
Website

Re: Complex Pagination using Newer/Older with Shift

etc wrote #326369:

Would introducing some ignore attribute be handy? Generally, tags like <txp:text /> output something, so testing them for emptiness is useless.

Seems like a good idea.

Offline

#40 2020-10-14 07:29:11

etc
Developer
Registered: 2010-11-11
Posts: 3,940
Website

Re: Complex Pagination using Newer/Older with Shift

philwareham wrote #326370:

Seems like a good idea.

Ok, to think about.

Offline

Board footer

Powered by FluxBB