Home » Labs » Display Random Posts In WordPress  

Display Random Posts In WordPress

Filed under Labs

Here is a block of code which will display posts as randomly in WordPress.This is one of the simple loop to show Random Posts In WordPress.

WordPress Code for Random Posts

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

Posts you may like: