Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2013-03-16 07:58:09

maratnugmanov
Member
From: Russia / Kazakhstan
Registered: 2013-02-24
Posts: 54
Website

Fetch next article id?

There is a tag link_to_next and next_title, but if I need to fetch next article Id (and previous id). So how can I get it?

Offline

#2 2013-03-16 10:42:20

CeBe
Plugin Author
From: Caen - Fr
Registered: 2010-06-25
Posts: 345
Website

Re: Fetch next article id?

If, and only if, IDs are contiguous :

<txp:variable name="cur_id" value='<txp:article_id />' />

<txp:php>
  global $variable ;
  $variable[ 'next_art_id' ] = strval( (int)$variable[ 'cur_id' ] + 1 ) ; // next article ID
  $variable[ 'prev_art_id' ] = strval( (int)$variable[ 'cur_id' ] - 1 ) ; // previous article ID
</txp:php>

<txp:article_custom id='<txp:variable name="next_art_id" />' />
<txp:article_custom id='<txp:variable name="prev_art_id" />' />

Offline

#3 2013-03-16 11:22:48

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

Re: Fetch next article id?

CeBe wrote:

If, and only if, IDs are contiguous

That’s very restrictive, especially for non-standard sort attributes. This prev/next id feature should be in the core, but if you don’t mind using a plugin, there is etc_link_to. It includes <txp:etc_link_id /> tag, respects any sort order and allows linking also to first/last/range articles. In some cases there can be performance cons (see the discussion here), but they aren’t noticeable before you reach 10000 articles or so, and I will take care of it in some next version.

Offline

#4 2013-03-16 14:02:57

maratnugmanov
Member
From: Russia / Kazakhstan
Registered: 2013-02-24
Posts: 54
Website

Re: Fetch next article id?

CeBe wrote:

If, and only if, IDs are contiguous…

I cannot guarantee that they will be contiguous, I’m pretty sure they won’t be. Even now – in 3 days after website launch the IDs are all scattered across the different sections.

Offline

#5 2013-03-16 14:11:30

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: Fetch next article id?

etc wrote:

This prev/next id feature should be in the core

It indeed should. I would add it right now, but can’t on top of the current system without introducing bugs. The pagination uses the parser’s second-pass feature, so that links can be used before the actual article list that defines the sorting criteria. Adding new tags to the mix increases the likeness of errors. For instance, things will go south if you try to use such tag as an attribute value before the article list is defined. It just doesn’t work. The tag attribute eats the tag, and doesn’t get the ID.

As such, we can’t freely add stuff to the pagination, not as long as it needs to be processed before listing. Any new feature just adds more weird behaviors on top of the old ones.

I personally am on boat for removing the second-pass and before list processing, allowing the use of pageby attribute where the pagination is needed before the list. I don’t like the second-pass bind idea at all, or adding alternative to it; such system can not work without added issues.

Offline

#6 2013-03-16 16:39:19

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

Re: Fetch next article id?

Gocom wrote:

For instance, things will go south if you try to use such tag as an attribute value before the article list is defined. It just doesn’t work. The tag attribute eats the tag, and doesn’t get the ID.

Yes, but isn’t that true for the existing prev/next_title tags (though they are less likely to be used as attributes)? If so, why worry, one cannot be a little pregnant anyway.

Maybe, tags need some order attribute, like plugins do, but it might be a nightmare to implement.

Offline

#7 2013-03-16 18:23:21

CeBe
Plugin Author
From: Caen - Fr
Registered: 2010-06-25
Posts: 345
Website

Re: Fetch next article id?

maratnugmanov a écrit:

I cannot guarantee that they will be contiguous, I’m pretty sure they won’t be.

Well… let’s say that I didn’t fully understand the question :p

Offline

Board footer

Powered by FluxBB