Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2009-01-25 06:36:41

verum
Member
Registered: 2007-01-28
Posts: 21

Display random article, Keep prev/next navigation intact

I’ve searched near and far on this, but no dice. So I’m posting for help.

I’m using <txp:link_to_next> and <txp:link_to_prev> to allow for navigation between articles along a timeline. I also want to provide a link that will go to a random article. If I try to use a page with an article list of 1 random article using sort=“rand()” it fetches a random article as intended. BUT. Now the prev / next links don’t work anymore (they just reload the existing page).

Is there a better method to call a random article with a link, but then allow the user to continue traveling along the timeline of articles using <txp:link_to_next> and <txp:link_to_prev>?

Thanks for any input!

Offline

#2 2009-01-25 17:08:28

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

Re: Display random article, Keep prev/next navigation intact

link_to_next and link_to_prev only work on individual article pages, and you are displaying your random article as an article list, that’s why they don’t work anymore. You’d have to display your random article as an individual article to make the links to next and prev work again.

Offline

#3 2009-01-25 17:59:15

JanDW
Plugin Author
From: Providence, RI, USA
Registered: 2008-07-18
Posts: 327
Website

Re: Display random article, Keep prev/next navigation intact

or you could use <txp:newer /> and <txp:older /> , I think?


TXPDream – A Textpattern Tag Library for Adobe Dreamweaver. (updated for 4.2.0) | jdw_if_ajax – Only serve certain parts of a page when requested with AJAX

Offline

#4 2009-01-25 20:56:45

verum
Member
Registered: 2007-01-28
Posts: 21

Re: Display random article, Keep prev/next navigation intact

Thanks for your input, both of you. I’d imagine txp:newer wouldn’t work because from my reading, it’s contextual and only shows the next/prev article in the current sort order, which is random.

So I’m interested in not using a list but rather a single article. But how do I go about directing the user to the permalink page for a random article?

In other words: Els, how do I do what you mentioned? ;)

Last edited by verum (2009-01-25 20:57:56)

Offline

#5 2009-01-25 21:37:08

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

Re: Display random article, Keep prev/next navigation intact

verum wrote:

In other words: Els, how do I do what you mentioned? ;)

How (and where) are you calling the random article now?

Offline

#6 2009-01-25 22:35:46

verum
Member
Registered: 2007-01-28
Posts: 21

Re: Display random article, Keep prev/next navigation intact

Right now I have a link in the default article form that points to ../?s=random which uses a page called random. This page contains a <txp:article_custom> tag that calls for a random article (limited to 1 so only 1 article comes up).

I KNOW there’s gotta be a simple, more streamlined way to handle this… haha

Offline

#7 2009-01-28 10:26:22

verum
Member
Registered: 2007-01-28
Posts: 21

Re: Display random article, Keep prev/next navigation intact

Any input on this? Els/anyone?

Please? ;)

Offline

#8 2009-01-28 13:44:52

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

Re: Display random article, Keep prev/next navigation intact

Hi verum

calling a link like /?s=random gives you an article list even if you set limit=1, an individual article must have a link like this (i think you are on messy link mode) : /?id=XX , where xx is an article id.

Cheers

Offline

#9 2009-01-28 14:01:39

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,730
Website

Re: Display random article, Keep prev/next navigation intact

How about putting this in your page template (txp v4.07+):

<txp:article_custom section="my-section" limit="1" sort="rand()">
  <txp:permlink><txp:title /></txp:permlink>
</txp:article_custom>

That should generate a link to a randomly selected article in the section “my-section”. When you arrive on the page I guess the next and previous should work as normal, no?


TXP Builders – finely-crafted code, design and txp

Offline

#10 2009-01-28 18:07:01

verum
Member
Registered: 2007-01-28
Posts: 21

Re: Display random article, Keep prev/next navigation intact

jakob wrote:

How about putting this in your page template (txp v4.07+):

<txp:article_custom section="my-section" limit="1" sort="rand()">
  <txp:permlink><txp:title /></txp:permlink>
</txp:article_custom>

p. That should generate a link to a randomly selected article in the section “my-section”. When you arrive on the page I guess the next and previous should work as normal, no?

It took some tweaking to work with my specific setup, but that approach works! Thanks very much to everyone who weighed in. All good info!

Offline

Board footer

Powered by FluxBB