By James Kanjo
Previously, before the order="random" attribute was available, there was no way to have a link which would display a random page.
The workaround used was the "single block of many pages" technique.
However, since the creation of this new attribute, it has become possible to use the ListPages module to create this.
[[module ListPages category="*" order="random" limit="1" range="others"]] [%%link%% Random page!] [[/module]]
In some web-browsers, the URL is shown as the user hovers the mouse over it. If you don't want the user to see the URL of the page on a mouse-hover, then you should create a "Random Page" page containing the following code:
[[module ListPages category="*" order="random" limit="1" range="others"]] [[iframe http://snippets.wdfiles.com/local--code/code:iframe-redirect#%%link%%]] [[/module]]
Then you make your "random link" link to that page.
Limitations and their solutions
Due to the nature of the order="random" attribute, the "random" page is not selected on the spot (it changes every 60 seconds).
The solution to this limitation would be to place it in the side bar, because the link is different on every page loaded. More explained, you can click the link in the side bar, and the loaded page will have a fresh new link in the same side navigator (so you can click it again).
Thanks to James Kanjo putting random page link in the top bar is also possible. The trick is that closing module brackets ([[/module]]), must be put AFTER the other links or buttons you have in your top bar, i.e. all other links and buttons must be placed inside the ListPages module.
[[module ListPages category="whatever category" order="random" limit="1" skipCurrent="true"]] * [%%link%% Random page] * Home * Whatever link * Whatever link * Print button * Edit button * Any other button or link [[/module]]
It is not necessary that Random page link gets the first on the list. You can put it wherever you want, but it must stay inside module brackets.
[[module ListPages category="whatever category" order="random" limit="1" skipCurrent="true"]] * Home * Whatever link * Whatever link * **[%%link%% Random page]** * Print button * Edit button * Any other button or link [[/module]]
Thanks to tsangk for this great snippet: conditional-blocks
text above inserted with:
[[include :snippets:if START |unique=1|type=equal|var1=%%name%%|var2=conditional-blocks]]
**##red|Thanks to tsangk for this great snippet:##** [[[code:conditional-blocks]]]
[[include :snippets:if END]]
Other snippets posted by James Kanjo
Extended NewPage Module - 11 Dec 2012 20:42
iframe Redirect - 30 Jul 2012 22:41
Per Category CSS Module - 06 Mar 2012 03:38
Video Player - 16 Feb 2012 01:50
Specific Users Only Include - 16 Feb 2012 01:43
Remove Duplications - 16 Feb 2012 01:39
RegExp Date Wizard - 16 Feb 2012 01:39
Quoted Blockquotes - 16 Feb 2012 01:33
NewPage Button - 16 Feb 2012 01:26
MP3 Player - 16 Feb 2012 01:25
iframe embed - 16 Feb 2012 01:08
Random Page - 18 May 2011 09:50
Redirect - 11 Feb 2010 10:00
Rate this solution
If you think this solution is useful — rate it up!