Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
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
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
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.
Piwik Dashboard, Google Analytics Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker
Offline
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
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
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)
Piwik Dashboard, Google Analytics Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker
Offline
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
Pages: 1