How To Create A Page That Shows Random Posts In Wordpress

Have you even been to a site and saw this cool feature ? They have a link in their top navigation to something like Stumble ! or Read Random Articles, or some other creative text. 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 post to create a custom page template, and simply paste this code in there:

"<?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; ?> "

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.
Post a Comment (0)
Previous Post Next Post