Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2024-01-23 07:50:42

Kjeld
Member
From: Tokyo, Japan
Registered: 2005-02-05
Posts: 453
Website

Problems with Pagination (txp:pages and custom fields)

I recently changed pagination on my site from etc-pagination to txp:pages.

The new pagination works fine for lists of articles organized by category, but I seem to have missed something to make it work for articles organized by a custom field.

A. Description of the Problem

A list for the category “customs” gives me the following links in pagination:

  1. https://www.oldphotosjapan.com/category/customs
  2. https://www.oldphotosjapan.com/category/customs/?pg=2
  3. https://www.oldphotosjapan.com/category/customs/?pg=3
    etc.

This is correct.

But a list for “Outside” in the custom field “location” gives me the following links in pagination:

  1. https://www.oldphotosjapan.com/photos/?location=Outside
  2. https://www.oldphotosjapan.com/photos/?pg=2
  3. https://www.oldphotosjapan.com/photos/?pg=3

This is broken.

I am using version 4.8.7.

B. Code

This is the code on the archive page:

<txp:if_search>
<txp:output_form form="display_search" />
<txp:else />
<txp:if_article_list>
<txp:if_section name="about">
<txp:output_form form="display_list_article" />
<txp:else />
<txp:output_form form="display_list_photo" />
</txp:if_section>

This is the relevant code in the form display_list_article

<txp:article form="card_article" limit="12" sort="url_title" match="category,artist,publisher,period,location,medium,translator" />

This is the relevant code in the form display_list_photo

<txp:article form="card_photo" limit="24" match="category,artist,publisher,period,location,medium,translator" />

And this is my pagination code:

<!-- /START PAGINATION -->
<txp:pages pg showalways="2" link="" evaluate="5,2,8,4,6">
    <nav aria-label="Page navigation">
        <ul class="pagination justify-content-center mt-5">
            <txp:newer showalways><li class="page-item"><a class="page-link" rel="prev" href="<txp:yield item="url" />" title="Go to previous page" aria-label="Go to previous page">&laquo;</a></li></txp:newer>
            <txp:newer shift><li class="page-item"><a href="<txp:yield item="url" />" class="page-link" 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"><li class="page-item" role="separator" title="More pages" aria-label="More pages"><span class="page-link">…</span></li></txp:newer>
            <txp:newer total shift="2"><li class="page-item"><a href="<txp:yield item="url" />" class="page-link" 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="page-item active"><span class="page-link" title="Current page" aria-current="page"><txp:yield item="page" /></span></li></txp:pages>
            <txp:older total shift="2"><li class="page-item"><a href="<txp:yield item="url" />" class="page-link" 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"><li class="page-item" role="separator" title="More pages" aria-label="More pages"><span class="page-link">…</span></li></txp:older>
            <txp:older shift><li class="page-item"><a href="<txp:yield item="url" />" class="page-link" 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>
            <txp:older showalways><li class="page-item"><a class="page-link" rel="next" href="<txp:yield item="url" />" title="Go to next page" aria-label="Go to next page">&raquo;</a></li></txp:older>
        </ul>
    </nav>
</txp:pages>
<!-- /END PAGINATION -->

C. Question

What must I change?

Last edited by Kjeld (2024-01-23 07:52:14)


Old Photos of Japan – Japan in the 1850s~1960s (100% txp)
MeijiShowa – Stock photos of Japan in the 1850s~1960s (100% txp)
JapaneseStreets.com – Japanese street fashion (mostly txp)

Offline

#2 2024-01-23 09:12:55

etc
Developer
Registered: 2010-11-11
Posts: 5,235
Website GitHub

Re: Problems with Pagination (txp:pages and custom fields)

I think you need to set the links context here:

<txp:page_url context="location">
<!-- /START PAGINATION -->
...
<!-- /END PAGINATION -->
</txp:page_url>

Should <txp:pages /> inherit all URL parameters by default? Dunno, maybe.

Offline

#3 2024-01-23 10:57:40

Kjeld
Member
From: Tokyo, Japan
Registered: 2005-02-05
Posts: 453
Website

Re: Problems with Pagination (txp:pages and custom fields)

etc wrote #336453:

I think you need to set the links context here:

<txp:page_url context="location">...

Should <txp:pages /> inherit all URL parameters by default? Dunno, maybe.

Thank you. That worked!

It now looks like this:

<!-- /START PAGINATION -->
<txp:page_url context="artist,publisher,period,location,medium,translator">
<txp:pages pg showalways="2" link="" evaluate="5,2,8,4,6">
…
</txp:pages>
</txp:page_url>
<!-- /END PAGINATION -->

In response to your note, It seems <txp:pages /> should inherit all URL parameters by default. Is there a reason not to do so?

Last edited by Kjeld (2024-01-23 11:03:35)


Old Photos of Japan – Japan in the 1850s~1960s (100% txp)
MeijiShowa – Stock photos of Japan in the 1850s~1960s (100% txp)
JapaneseStreets.com – Japanese street fashion (mostly txp)

Offline

#4 2024-01-23 11:31:39

etc
Developer
Registered: 2010-11-11
Posts: 5,235
Website GitHub

Re: Problems with Pagination (txp:pages and custom fields)

Kjeld wrote #336457:

In response to your note, It seems <txp:pages /> should inherit all URL parameters by default. Is there a reason not to do so?

The reason is vaguely SEO. Some URL parameters might be not related to the pagination or appended erroneously. Retaining them in pagination links could result in duplicate URLs. Will think of it.

Offline

Board footer

Powered by FluxBB