[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 577
  • Last Modified:

WordPress Random Post Code

I'm not a programmer. I've been messing around with this for a couple of days after reading many articles online. I hope one of you experts can help me. I'm trying to create a page on a WordPress blog to display all post thumbnails in random order.

The blog is here http://meatbeerbabes.com

The "random post" link on the top-right hand of the header is a "page" that is linked to a page template I created (page-rando-post.php) and it should produce a page similar to the one index.php produces but it should sort all posts randomly.

I do appreciate your help. I've attached two files, index.php and the page template I created (experimented with), page-random-post.php.

Thank you!
index.php
page-random-post.php
0
westarinfo
Asked:
westarinfo
  • 2
1 Solution
 
sivagnanam chandrakanthCommented:
Add this before if(have_post())

query_posts(array(
      'showposts' => 6, //no of posts to display
      'orderby' => 'rand',
'category_name' => 'News' //You can insert any category name //remove tis if you dont need
));
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now