- April 30, 2013
- Posted by: Admin
- Category: Wordpress
How to display random posts in custom page in wordpress
This is amazing requirement from one of my client. In the requirement, they want to display random posts in one of the custom page in their website. So I have done some R & D for it but not found exact article. So I have made my own way. Each time you refresh custom page, you will get different posts.
Step : First of all, you have to create custom page template. Then you have to paste below code in it.
query_posts(array('orderby' => 'rand', 'showposts' => 10));
if (have_posts()) :
while (have_posts()) : the_post(); ?>
<h1><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h1>
<?php the_content(); ?>