Knowledgebase
How to Create a Page that Displays Random Posts
Posted by Susan Tyson on 08 June 2016 05:51 PM

Have you ever been to a site and saw this cool feature? They have a link in their top navigation to something like Stumbe! or Read Random Articles, or some other creative text. When you click on that link, it takes you to a page that displays one random page. Each time you refresh, you are delivered with a new post. Well this trick is just for you then.

You would need to follow the trick #1 in this article to create a custom page template. And simply paste this code in there:

 
01 <?php
02 query_posts(array('orderby' => 'rand', 'showposts' => 1));
03 if (have_posts()) :
04 while (have_posts()) : the_post(); ?>
05  
06 <h1><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h1>
07  
08 <?php the_content(); ?>
09  
10 <?php endwhile;
11 endif; ?>

This is a simple WordPress Loop that is running a query to display random posts and the number 1 in there is telling WordPress to only show 1 post. You can change that number, but most of the time people do it one post a time.

 

(0 vote(s))
Helpful
Not helpful

Comments (12)
Martha
13 July 2016 08:33 PM
that we have to be pro-Jew, and it sounds like he is saying we will soon be asked to be prou-omosexhal too.One other thing: I couldn't believe the attempt to belittle the significance of Lenin's 1/4 Jewishness. In most countries, unless you are 100% the majority ethnic group, you are treated as part of the minority group. That's true whether the minority group is privileged, as minorities are in the West, or whether minority groups are subject to persecution. As a 1/4 Jew, Lenin could have been blamed for the actions of Jews. That seems like it would have to be the salient fact in his mind.
Tina
13 July 2016 08:43 PM
Hello my family member! I wish to say that this post is amazing, nice written and come with almost all sinnificagt infos. Iˇ¦d like to look more posts like this .
Midge
14 July 2016 04:59 PM
That's an inventive answer to an <a href="http://pnwlborfxb.com">inernestitg</a> question
Buckie
17 July 2016 01:39 PM
If you're reading this, you're all set, parednr! http://cnjgnci.com [url=http://hcczhflh.com]hcczhflh[/url] [link=http://eayddn.com]eayddn[/link]
Tiger
17 July 2016 01:39 PM
This has made my day. I wish all poingtss were this good. http://mxfqyoma.com [url=http://fwmpdczkzx.com]fwmpdczkzx[/url] [link=http://itcpodxfd.com]itcpodxfd[/link]
Rain
18 July 2016 08:23 PM
The genius store <a href="http://opurxh.com">cadlel,</a> they're running out of you.
Mimosa
18 July 2016 08:23 PM
I'm impressed! You've managed the almost <a href="http://usxkuv.com">imsepsiblo.</a>
Kenisha
19 July 2016 02:06 AM
You have more useful info than the British had colonies pr-IIWeW. http://hfywuhrhvt.com [url=http://elevwgethq.com]elevwgethq[/url] [link=http://uedmhnzjvpu.com]uedmhnzjvpu[/link]
nrlxcgpaili
26 August 2017 10:17 PM
direct payday loan lenders <a href="http://cashadvances2017.com"> guaranteed payday loans</a> &lt;a href=&quot;http://cashadvances2017.com&quot;&gt; what is a payday loan&lt;/a&gt; <a href=http://cashadvances2017.com>payday loans no credit check</a> payday loan store
nqxhugpaili
10 September 2017 06:36 AM
payday loan direct lender <a href="http://paydayloans2017.com"> payday loans</a> &lt;a href=&quot;http://paydayloans2017.com&quot;&gt; payday loan online&lt;/a&gt; <a href=http://paydayloans2017.com>payday loans near me</a> usa payday loans
nnhybfpaili
14 September 2017 10:25 PM
payday loans online no credit check instant approval <a href="http://paydayloans2017.com"> best payday loans</a> &lt;a href=&quot;http://paydayloans2017.com&quot;&gt; payday loans direct lender&lt;/a&gt; <a href=http://paydayloans2017.com>online payday loan</a> usa payday loans
Uplidly
19 October 2023 06:15 AM
Proviron can be used to help you gain muscle and strength <a href=http://viagr.art>i took 200mg viagra</a>
Post a new comment
 
 
Full Name:
Email:
Comments:
CAPTCHA Verification 
 
Please enter the text you see in the image into the textbox below (we use this to prevent automated submissions).