How to display random posts in custom page in wordpress

Topics focus on Web Developments, Programming, Database, Digital Marketing Tutorials, Code Snippets, SEO, Social Media Marketing and Inspirational articles.

How to display random posts in custom page in wordpress

How to display random posts in custom page in 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.

1
2
3
4
5
6
7
8
9
10
11
12
<?php
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(); ?>
 
	<?php endwhile;
endif; 
?>

Add comment


 

Pin It on Pinterest

Share This