Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2012-06-26 18:41:07

wet
Developer Emeritus
From: Schoerfling, Austria
Registered: 2005-06-06
Posts: 3,330
Website Mastodon

r3847: link_to_prev and link_to_next adhere to a custom sort order

For many years we used to claim that Textpattern was not only a blog engine but also a full-featured CMS.

That was a lie ;)

At the very heart if it, Textpattern always assumed a chronological order of articles and browsed from current to next or previous articles by looking at the “Posted” date even if you wanted something like <txp:article sort="Title asc" />.

This has changed with r3847. Individual articles are now browsable by the article list’s sort order.

For simple cases, no markup changes are required. More complex cases may require an additional <txp:article pgonly="1" ... /> tag near the top of the page template.

Some examples:

The simple case

<!doctype html>
<html>
<head><title>1</title></head>
<body>

<txp:article />

<txp:if_individual_article>
<txp:link_to_next><txp:next_title/></txp:link_to_next>
<txp:link_to_prev><txp:prev_title/></txp:link_to_prev>
</txp:if_individual_article>
</body>

Sort order defaults to “Posted desc”. The <txp:article /> tag establishes this sort order and <txp:link_to_next> / <txp:link_to_prev> browse in chronological order.

This is how Textpattern 4.4.1 works. This will not change in Textpattern 4.5.

Custom sort order

<!doctype html>
<html>
<head><title>1</title></head>
<body>

<txp:article sort="Title asc" />

<txp:if_individual_article>
<txp:link_to_next><txp:next_title/></txp:link_to_next>
<txp:link_to_prev><txp:prev_title/></txp:link_to_prev>
</txp:if_individual_article>
</body>

Sort order is explicitly set to “Title asc”. The <txp:article /> tag establishes this sort order and <txp:link_to_next> / <txp:link_to_prev> browse by article titles in alphabetical order. No additional markup required.

New to Textpattern 4.5.

Custom sort order, early navigation, incorrect navigation

<!doctype html>
<html>
<head><title>1</title></head>
<body>
<txp:if_individual_article>
<txp:link_to_next><txp:next_title/></txp:link_to_next>
<txp:link_to_prev><txp:prev_title/></txp:link_to_prev>
</txp:if_individual_article>

<txp:article sort="Title asc" />

</body>

Sort order is explicitly set to “Title asc”. As <txp:article /> establishes this sort order after <txp:link_to_next> / <txp:link_to_prev> have rendered their output, <txp:link_to_next> / <txp:link_to_prev> lack this information and fall back to the default chronological sort order of “Posted desc”.

We need a helper…

Custom sort order, early navigation, correct navigation

<!doctype html>
<html>
<head><title>1</title></head>
<body>

<txp:article sort="Title asc" pgonly="1" />

<txp:if_individual_article>
<txp:link_to_next><txp:next_title/></txp:link_to_next>
<txp:link_to_prev><txp:prev_title/></txp:link_to_prev>
</txp:if_individual_article>

<txp:article sort="Title asc" />

</body>

“pgonly” establishes the desired sort order without rendering any output.

Restrictions

  • Currently we do not recognize complex sort orders like MySQL functions MIN(custom_1,custom2) or multiple sort columns (custom_1 asc, custom_2 desc) and fallback to a chronological order on such occasions.
  • The sort column must contain distinct values (e.g. 1, 2, 4, 7, 99; not 1, 2, 2, 2, 2, 2, 4, 7, 99). Otherwise, the next/prev links will choose one arbitrary neighbour with a lower/higher value.

Offline

#2 2012-06-26 19:17:45

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: r3847: link_to_prev and link_to_next adhere to a custom sort order

Niiiice! Thank you! Under Restrictions I especially like the “currently”… ;)

Offline

#3 2012-06-27 07:33:45

Dragondz
Moderator
From: Algérie
Registered: 2005-06-12
Posts: 1,538
Website GitHub Twitter

Re: r3847: link_to_prev and link_to_next adhere to a custom sort order

nice feature!

I suppose that rand() sort order is not working, it falls into complex sort orders!

Offline

#4 2012-06-27 11:11:42

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,306

Re: r3847: link_to_prev and link_to_next adhere to a custom sort order

Thanks! Will make many more to stick with TXP.


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#5 2012-07-09 05:01:55

ax
Plugin Author
From: Germany
Registered: 2009-08-19
Posts: 165

Re: r3847: link_to_prev and link_to_next adhere to a custom sort order

wet wrote:

This is how Textpattern 4.4.1 works. This will not change in Textpattern 4.5.

Not quite. prev/next was restricted to grab articles from viewed section only, but not anymore.

Offline

#6 2012-07-09 05:24:48

wet
Developer Emeritus
From: Schoerfling, Austria
Registered: 2005-06-06
Posts: 3,330
Website Mastodon

Re: r3847: link_to_prev and link_to_next adhere to a custom sort order

Good catch! Please try r3945.

Offline

#7 2012-07-09 05:37:21

ax
Plugin Author
From: Germany
Registered: 2009-08-19
Posts: 165

Re: r3847: link_to_prev and link_to_next adhere to a custom sort order

Much better now :)) Thanks for the quick fix!

Offline

#8 2012-07-09 21:46:40

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: r3847: link_to_prev and link_to_next adhere to a custom sort order

Edit: Never mind, must be the code. If I change it to

                <p id="paginator">
                    <a id="paginator-l" href="<txp:link_to_prev />" title="<txp:text item='prev' />" class="button">← <txp:prev_title /></a>
                    <a id="paginator-r" href="<txp:link_to_next />" title="<txp:text item='next' />" class="button"><txp:next_title /> →</a>
                </p>

the errors are gone.

Edit 2: Hmm… it’s this part that is causing the errors (only after the upgrade):

                <txp:variable name="prev" value='<txp:prev_title />' />
                <txp:variable name="next" value='<txp:next_title />' />

But now I’m probably in the wrong thread…

=============
Upgraded to the latest nightly. On an individual article page I get these errors:

Tag foutmelding <txp:prev_title /> ->  Notice: Undefined index:  prev_title bij het verwerken van module “geen” op pagina “default”

textpattern/lib/txplib_publish.php:405 prev_title()
textpattern/lib/txplib_publish.php:305 processTags()
textpattern/lib/txplib_misc.php:1258 parse()
textpattern/lib/txplib_publish.php:405 splat()
textpattern/lib/txplib_publish.php:305 processTags()
textpattern/publish/taghandlers.php:3264 parse()
textpattern/lib/txplib_publish.php:405 if_article_list()
textpattern/lib/txplib_publish.php:318 processTags()
textpattern/publish.php:544 parse()
index.php:80 textpattern()

Tag foutmelding <txp:next_title /> ->  Notice: Undefined index:  next_title bij het verwerken van module “geen” op pagina “default”

textpattern/lib/txplib_publish.php:405 next_title()
textpattern/lib/txplib_publish.php:305 processTags()
textpattern/lib/txplib_misc.php:1258 parse()
textpattern/lib/txplib_publish.php:405 splat()
textpattern/lib/txplib_publish.php:305 processTags()
textpattern/publish/taghandlers.php:3264 parse()
textpattern/lib/txplib_publish.php:405 if_article_list()
textpattern/lib/txplib_publish.php:318 processTags()
textpattern/publish.php:544 parse()
index.php:80 textpattern()

The code on the page is (I think) the new default (at least I don’t remember changing it), in the ‘else’ part of if_article_list:

                <p id="paginator">

                <txp:variable name="prev" value='<txp:prev_title />' />
                <txp:variable name="next" value='<txp:next_title />' />

                <txp:if_variable name="prev" value="">
                    <span id="paginator-l" class="button disabled">← <txp:text item="older" /></span>
                <txp:else />
                    <a id="paginator-l" href="<txp:link_to_prev />" title="<txp:text item='prev' />" class="button">← <txp:prev_title /></a>
                </txp:if_variable>
                <txp:if_variable name="next" value="">
                    <span id="paginator-r" class="button disabled"><txp:text item="newer" /> →</span>
                <txp:else />
                        <a id="paginator-r" href="<txp:link_to_next />" title="<txp:text item='next' />" class="button"><txp:next_title /> →</a>
                </txp:if_variable>

                </p>

Last edited by els (2012-07-09 22:05:08)

Offline

#9 2012-07-10 07:43:44

wet
Developer Emeritus
From: Schoerfling, Austria
Registered: 2005-06-06
Posts: 3,330
Website Mastodon

Re: r3847: link_to_prev and link_to_next adhere to a custom sort order

Els wrote:

But now I’m probably in the wrong thread…

Els, you are perfectly on-topic. Please try r3950.

Offline

#10 2012-07-10 19:48:31

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: r3847: link_to_prev and link_to_next adhere to a custom sort order

wet wrote:

Please try r3950.

Fixed! Thanks :)

Offline

#11 2012-07-10 20:36:25

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: r3847: link_to_prev and link_to_next adhere to a custom sort order

Using the pagination code in the default page template as posted above (and the new taghandlers.php), link_to_prev and link_to_next are linking to the current article, no matter which value is used for the sort attribute.

Offline

#12 2012-07-13 11:34:57

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: r3847: link_to_prev and link_to_next adhere to a custom sort order

Els wrote:

Using the pagination code in the default page template as posted above (and the new taghandlers.php), link_to_prev and link_to_next are linking to the current article, no matter which value is used for the sort attribute.

Is this a bug or am I doing something wrong?

Offline

Board footer

Powered by FluxBB