Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
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
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
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
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
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
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
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
Pages: 1