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(); ?>
06 <h1><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h1>
08 <?php the_content(); ?>
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))
Not helpful

Comments (12)
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.
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 .
14 July 2016 04:59 PM
That's an inventive answer to an <a href="">inernestitg</a> question
17 July 2016 01:39 PM
If you're reading this, you're all set, parednr! [url=]hcczhflh[/url] [link=]eayddn[/link]
17 July 2016 01:39 PM
This has made my day. I wish all poingtss were this good. [url=]fwmpdczkzx[/url] [link=]itcpodxfd[/link]
18 July 2016 08:23 PM
The genius store <a href="">cadlel,</a> they're running out of you.
18 July 2016 08:23 PM
I'm impressed! You've managed the almost <a href="">imsepsiblo.</a>
19 July 2016 02:06 AM
You have more useful info than the British had colonies pr-IIWeW. [url=]elevwgethq[/url] [link=]uedmhnzjvpu[/link]
26 August 2017 10:17 PM
direct payday loan lenders <a href=""> guaranteed payday loans</a> &lt;a href=&quot;;&gt; what is a payday loan&lt;/a&gt; <a href=>payday loans no credit check</a> payday loan store
10 September 2017 06:36 AM
payday loan direct lender <a href=""> payday loans</a> &lt;a href=&quot;;&gt; payday loan online&lt;/a&gt; <a href=>payday loans near me</a> usa payday loans
14 September 2017 10:25 PM
payday loans online no credit check instant approval <a href=""> best payday loans</a> &lt;a href=&quot;;&gt; payday loans direct lender&lt;/a&gt; <a href=>online payday loan</a> usa payday loans
19 October 2023 06:15 AM
Proviron can be used to help you gain muscle and strength <a href=>i took 200mg viagra</a>
Post a new comment
Full Name:
CAPTCHA Verification 
Please enter the text you see in the image into the textbox below (we use this to prevent automated submissions).