We mentioned a plugin that allows you to have Stumbleupon like Browsing system in WordPress. The problem with that plugin is that it redirects a user to the actual URL which can create some user end issues such as page not loading, redirect error etc. In this post we will show you how you can create a page that displays a random post in WordPress, so you can simply send your user to that page and they can read a new post every time they refresh the page.
EDIT (11/29/2012): We are no longer using this technique because it prevented us from showing proper social buttons. Instead we have a new method that allows you to redirect the user to a random post using /random/. This method is much better. Read more about How to redirect users to a random post in WordPress.
Step 1: of this tutorial is to create a custom page template in WordPress.
Step 2: Add the following code in your custom page template:
<?php query_posts(array('orderby' => 'rand', 'showposts' => 1)); if (have_posts()) : while (have_posts()) : the_post(); ?> <h1><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h1> <?php the_content(); ?> <?php endwhile; endif; ?>
That’s it. Depending on the name that you choose for the page, you can now create a button in your navbar for users to click on that page and view a random post.
(Simply refresh a page to see a new post)