Wordpress random posts

/ Published in: PHP
Save to your folder(s)

Display random posts without a plugin

Copy this code and paste it in your HTML
  1. <ul>
  2. <?php $rand_posts = get_posts('numberposts=5&orderby=rand');
  3. foreach( $rand_posts as $post ) : ?>
  4. <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
  5. <?php endforeach; ?>
  6. </ul>

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.