Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2019-12-17 00:14:58

gilibaus
Member
From: Milan, Italy
Registered: 2013-08-14
Posts: 71
Website

Link to last published article

Sorry if this has been asked before, searched the forum but could not find any answer. I publish a new article every week and all of them belong to the same section. I need a single URL that always points to the last published individual article in that section. Any hint? Thanks.

Last edited by gilibaus (2019-12-17 00:16:09)

Offline

#2 2019-12-17 05:34:12

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 8,281
Website

Re: Link to last published article

gilibaus wrote #320575:

Sorry if this has been asked before, searched the forum but could not find any answer. I publish a new article every week and all of them belong to the same section. I need a single URL that always points to the last published individual article in that section. Any hint? Thanks.

That would be very bad as people would not be able to bookmark the individual article. One way would be to create a section (you can call it ‘latest’) and parse your latest article there using article_custom tag.


Yiannis
——————————
neme.org | hblack.net | LABS | State Machines | NeMe @ github | Covid-19; a resource
I do my best editing after I click on the submit button.

Offline

#3 2019-12-17 08:56:59

gilibaus
Member
From: Milan, Italy
Registered: 2013-08-14
Posts: 71
Website

Re: Link to last published article

colak wrote #320576:

That would be very bad as people would not be able to bookmark the individual article.

Thanks. No need to bookmark the individual article. It’s the latest episode of my podcast and the URL would be placed in email footer so that the reader can go to the latest episode, which is a normal behaviour. I had thought adding an URL parameter via adi_gps plugin. Is it a viable alternative?

Offline

#4 2019-12-17 09:24:33

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,473
Website

Re: Link to last published article

Maybe you want to check out if_first_article, if_last_article, or newer tags. I’m sure there are multiple possibilities for handling this.

Learning tag options/capabilities is your means to most ends. ;)

All tag pages have various examples in them. (Some could be improved, but that will gradually smooth out.)

Offline

#5 2019-12-17 09:32:21

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,473
Website

Re: Link to last published article

gilibaus wrote #320580:

It’s the latest episode of my podcast and the URL would be placed in email footer so that the reader can go to the latest episode.

Ah… The latest article will always be the last one published to a given section, so if you have a podcasts section like this, domain.tld/podcasts/, then that’s also the link to the latest article, so long as you’re only showing one article at a time in that section.

If you’re showing multiple podcasts in that section, then you might want to use the if_first_article tag I mentioned. Something like that. Maybe you have some ideas now.

Offline

#6 2019-12-17 09:37:07

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 9,775
Website

Re: Link to last published article

If you don’t mind the URL structure: example.org/articles?latest=1 you could do this in your page template:

<txp:variable name="is_latest"><txp:page_url type="latest" /></txp:variable>
...
<txp:if_variable name="is_latest" value="1">
    <txp:article limit="1" />
</txp:else>
   <txp:article />
</txp:if_variable>

No need for adi_gps.

Last edited by Bloke (2019-12-17 09:37:28)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#7 2019-12-18 03:55:06

gilibaus
Member
From: Milan, Italy
Registered: 2013-08-14
Posts: 71
Website

Re: Link to last published article

Bloke’s suggestion worked like a charm. Thanks everyone.

Offline

#8 2019-12-19 06:58:29

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

Re: Link to last published article

Bloke wrote #320584:

<txp:page_url type="latest" />.

Out of curiosity, is that an undocumented value for the type attribute here? And what exactly does it selects?

(I haven’t tried what it generates)


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

Offline

#9 2019-12-19 09:19:22

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 3,938
Website

Re: Link to last published article

phiw13 wrote #320600:

Out of curiosity, is that an undocumented value for the type attribute here?

Oleg recently introduced (or perhaps it was possible for a while but he recently revealed it like he often does in a forum post) the ability to use “page_url” to retrieve url query variables. In conjunction with txp:variable, it obviates the need for adi_gps / rah_gps.

If my memory serves me correctly, it also escapes the url query value so there shouldn’t be a sql injection risk. Is that right, Oleg?

An aside: even better, article_custom will be able to respond to url variables too, making it possible to filter list output not just on categories or sections but also other criteria. I’ll have to find the post again and write that up as a forthcoming tip.


TXP Builders – finely-crafted code, design and txp

Offline

#10 2019-12-19 09:44:23

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

Re: Link to last published article

jakob wrote #320602:

Oleg recently introduced (or perhaps it was possible for a while but he recently revealed it like he often does in a forum post) the ability to use “page_url” to retrieve url query variables.

It was in 4.7 and I have even documented it. RTFM, comrades ;-)

it also escapes the url query value so there shouldn’t be a sql injection risk. Is that right, Oleg?

It escapes it for HTML output by default, not for SQL injection, since no txp tag writes directly to db. Makes me think we could add db to global escape options.

Offline

Board footer

Powered by FluxBB