Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#21 2020-04-15 20:08:18

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

Re: Complex Pagination using Newer/Older with Shift

singaz wrote #322607:

When I am in the place of the “author”, pagination does not work.

Question: in the <txp: if_author> </ txp: if_author> section, should pagination work or not? I have not used it before and I do not know how to use it correctly.

The problem is probably not <txp:if_author /> but <txp:article_custom />. Try with <txp:article /> instead?

Offline

#22 2020-04-15 21:38:31

singaz
Member
From: Kyiv, Ukraine
Registered: 2017-03-12
Posts: 143

Re: Complex Pagination using Newer/Older with Shift

Yes! <txp: article /> works as it should!

The correct code is:

<txp:if_author>
	<txp:article form="article_list_author"/>
</txp:if_author>

My inattention and subtleties of work <txp: article /> and <txp: article_custom />.

Thank you Oleg!


Sorry my horror English. I’m learning textpattern, I’m learning English

Offline

#23 2020-05-04 11:53:27

hilaryaq
Plugin Author
Registered: 2006-08-20
Posts: 277
Website

Re: Complex Pagination using Newer/Older with Shift

Super cool thanks for this @michaelkpate! :)


…………………
I <3 txp
…………………

Offline

#24 2020-05-27 08:44:55

phiw13
Plugin Author
From: Japan
Registered: 2004-02-27
Posts: 2,146
Website

Re: Complex Pagination using Newer/Older with Shift

Heads up for anyone having issues with displaying the current page item with the code discussed in this thread (the line containing txp:newer shift="0"), see this thread instead.


Where is that emoji for a solar powered submarine when you need it ?

Offline

#25 2020-05-27 14:24:45

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

Re: Complex Pagination using Newer/Older with Shift

I’ve been working on the pagination used on Textpattern.com based on Michael’s original example and some additional help from Oleg. This is the latest code we have for Textpattern 4.8.0:

<txp:evaluate query='<txp:pages total /> > 1'>
    <txp:pages pg="pg" evaluate="5,2,8,4,6">
        <nav class="paginator" aria-label="Blog navigation">
            Pages:
            <txp:newer showalways link=""><a rel="prev" href="<txp:yield item="url" />" title="Go to previous page" aria-label="Go to previous page">Previous</a></txp:newer>
            <ul class="pagination">
                <txp:newer shift link=""><li><a href="<txp:yield item="url" />" title="Go to page <txp:yield item="page" />" aria-label="Go to page <txp:yield item="page" />"><txp:yield item="page" /></a></li></txp:newer>
                <txp:newer shift="-2" link=""><li role="separator" title="More pages" aria-label="More pages">…</li></txp:newer>
                <txp:newer total shift="2" link=""><li><a href="<txp:yield item="url" />" title="Go to page <txp:yield item="page" />" aria-label="Go to page <txp:yield item="page" />"><txp:yield item="page" /></a></li></txp:newer>
                <txp:newer shift="0" link=""><li class="current"><b title="Current page" aria-current="page"><txp:yield item="page" /></b></li></txp:newer>
                <txp:older total shift="2" link=""><li><a href="<txp:yield item="url" />" title="Go to page <txp:yield item="page" />" aria-label="Go to page <txp:yield item="page" />"><txp:yield item="page" /></a></li></txp:older>
                <txp:older shift="-2" link=""><li role="separator" title="More pages" aria-label="More pages">…</li></txp:older>
                <txp:older shift link=""><li><a href="<txp:yield item="url" />" title="Go to page <txp:yield item="page" /> (last page)" aria-label="Go to page <txp:yield item="page" /> (last page)"><txp:yield item="page" /></a></li></txp:older>
            </ul>
            <txp:older showalways link=""><a rel="next" href="<txp:yield item="url" />" title="Go to next page" aria-label="Go to next page">Next</a></txp:older>
        </nav>
    </txp:pages>
</txp:evaluate>

Main change from Michael’s original is wrapping it in…

<txp:evaluate query='<txp:pages total /> > 1'>

…only displays the pagination if more than one page is returned (otherwise you get a pagination widget with only 1 page on it which is a bit superfluous).

Other minor changes are mainly for accessibility additions.

And a more optimised version you can use in (upcoming) Textpattern 4.8.1 onwards (a slight change to how the current page is generated and a more succinct way of determining if more than 1 page exists):

<txp:pages pg showalways="2" evaluate="5,2,8,4,6">
    <nav class="paginator" aria-label="Blog navigation">
        Pages:
        <txp:newer showalways link=""><a rel="prev" href="<txp:yield item="url" />" title="Go to previous page" aria-label="Go to previous page">Previous</a></txp:newer>
        <ul class="pagination">
            <txp:newer shift link=""><li><a href="<txp:yield item="url" />" title="Go to page <txp:yield item="page" />" aria-label="Go to page <txp:yield item="page" />"><txp:yield item="page" /></a></li></txp:newer>
            <txp:newer shift="-2" link=""><li role="separator" title="More pages" aria-label="More pages">…</li></txp:newer>
            <txp:newer total shift="2" link=""><li><a href="<txp:yield item="url" />" title="Go to page <txp:yield item="page" />" aria-label="Go to page <txp:yield item="page" />"><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" link=""><li><a href="<txp:yield item="url" />" title="Go to page <txp:yield item="page" />" aria-label="Go to page <txp:yield item="page" />"><txp:yield item="page" /></a></li></txp:older>
            <txp:older shift="-2" link=""><li role="separator" title="More pages" aria-label="More pages">…</li></txp:older>
            <txp:older shift link=""><li><a href="<txp:yield item="url" />" title="Go to page <txp:yield item="page" /> (last page)" aria-label="Go to page <txp:yield item="page" /> (last page)"><txp:yield item="page" /></a></li></txp:older>
        </ul>
        <txp:older showalways link=""><a rel="next" href="<txp:yield item="url" />" title="Go to next page" aria-label="Go to next page">Next</a></txp:older>
    </nav>
</txp:pages>

EDIT: updated code following Oleg’s post below.

Last edited by philwareham (2020-05-28 10:29:17)

Offline

#26 2020-05-27 23:00:32

phiw13
Plugin Author
From: Japan
Registered: 2004-02-27
Posts: 2,146
Website

Re: Complex Pagination using Newer/Older with Shift

Oh, yes, checking for the a minimum of 2 pages before outputting the pagination bar is a good addition. I had not yet checked that out. Thank you (and Oleg) for that part.


Where is that emoji for a solar powered submarine when you need it ?

Offline

#27 2020-05-28 10:15:10

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

Re: Complex Pagination using Newer/Older with Shift

Both <txp:newer shift="0" /> and <txp:pages /> are working in 4.8.1 now, so the update should be automatic. Additionally, <txp:evaluate query='<txp:pages total /> > 1'>... check can be replaced with showalways attribute of pages container:

<txp:pages pg showalways="" evaluate="5,2,8,4,6">
    ...
</txp:pages>

And if you need a pagination bar only for n pages and above, set showalways="n".

Offline

#28 2020-05-28 10:25:30

phiw13
Plugin Author
From: Japan
Registered: 2004-02-27
Posts: 2,146
Website

Re: Complex Pagination using Newer/Older with Shift

etc wrote #323362:

Both <txp:newer shift="0" /> and <txp:pages /> are working in 4.8.1 now

that is good news, thank you. I’ll test it out tomorrow morning after giving the old body some rest.

Additionally, <txp:evaluate query='<txp:pages total /> > 1'>... check can be replaced with showalways attribute of pages container:

more magic awesomeness courtesy of Oleg :-) Thank you again.


Where is that emoji for a solar powered submarine when you need it ?

Offline

#29 2020-05-28 10:31:59

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

Re: Complex Pagination using Newer/Older with Shift

Thanks Oleg, I have now updated my previous code example with these changes.

Offline

#30 2020-05-29 08:13:16

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

Re: Complex Pagination using Newer/Older with Shift

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!

Offline

Board footer

Powered by FluxBB