Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2008-10-22 18:09:44

mwr
Member
From: Canada
Registered: 2006-01-31
Posts: 167
Website

Link to randomly selected article

When users arrive, I want them to see the latest article just as they would normally. But I want them to have the option of clicking on a link that changes the display to a randomly selected article. Ideally, they would be able to do this within various categories as well.

Can it be done?


Mark

Offline

#2 2008-10-22 18:48:36

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

Re: Link to randomly selected article

On the page:

<txp:article_custom limit="1" sort="rand()" form="randomarticle" />

(you can set section(s) and category/ies with the section and category attributes if you want)

Form ‘randomarticle’:

<txp:permlink>Click here for a random article</txp:permlink>

Offline

#3 2008-10-22 19:25:11

mwr
Member
From: Canada
Registered: 2006-01-31
Posts: 167
Website

Re: Link to randomly selected article

Thanks. That seems to be what I was looking for. Is it possible to have the randomly selected article appear on the front page instead of on its individual article page? Alternatively, I suppose I could design the look of individual article pages so that they give the appearance of doing this.

Maybe what I really need to do is display a random page, each with one article on it — if that makes any sense!

Last edited by mwr (2008-10-22 19:28:20)


Mark

Offline

#4 2008-10-22 19:28:20

MattD
Plugin Author
From: Monterey, California
Registered: 2008-03-21
Posts: 1,254
Website

Re: Link to randomly selected article

Change the randomarticle form to display what you want on the front page. If you want to hide the article until the link is clicked you could surround the hidden portions in a div and hide and display using javascript.


My Plugins

Piwik Dashboard, Google Analytics Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker

Offline

#5 2008-10-22 19:31:04

mwr
Member
From: Canada
Registered: 2006-01-31
Posts: 167
Website

Re: Link to randomly selected article

Matt

Thanks for the suggestions, but you’re getting out of my depth. Can you give me some examples?


Mark

Offline

#6 2008-10-22 21:15:27

the_ghost
Plugin Author
From: Minsk, The Republic of Belarus
Registered: 2007-07-26
Posts: 907
Website

Re: Link to randomly selected article

@mwr

If don’t want to show the link to random article when viewing some article, than just wrat txp:article_custom with condition txp:if_article_list

Ot what is your aim?


Providing help in hacking ATM! Come to courses and don’t forget to bring us notebook and hammer! What for notebook? What a kind of hacker you are without notebok?

Offline

#7 2008-10-22 22:41:46

MattD
Plugin Author
From: Monterey, California
Registered: 2008-03-21
Posts: 1,254
Website

Re: Link to randomly selected article

Building on Els example:
On the page

<a href="#" onclick="$('#hiddenArticle').toggle();return false;">View  Random Article</a>
<div id='hiddenArticle'><txp:article_custom limit="1" sort="rand()" form="AnyFormYouWant" /></div>

css

#hiddenArticle{display:none;}

using jQuery Toggle you can hide and show the article. Make sure you include jQuery in your page.

Last edited by MattD (2008-10-22 22:42:28)


My Plugins

Piwik Dashboard, Google Analytics Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker

Offline

#8 2008-10-23 16:44:55

mwr
Member
From: Canada
Registered: 2006-01-31
Posts: 167
Website

Re: Link to randomly selected article

Thanks for the suggestions, guys. I managed to figure it out for myself. Sorry if my questions seemed convoluted.


Mark

Offline

Board footer

Powered by FluxBB