Best 2 Know

The Ultimate Blogging Resource

  • Advertising
  • WebHosting
  • Contact Us
  • Blogger
    • Blogger Templates
    • Blogger Tutorials
  • Browser
    • Firefox
    • Google Chrome
  • Google
  • Internet
    • Facebook
    • Twitter
  • Thesis
  • Windows
  • WordPress
    • WordPress Themes
    • WordPress Plugins
  • More
    • Linux
    • Review
    • Solutions
    • Announcements

How to Display Random Posts

Want to display Random Posts on your WordPress Blog get more Page views and Help your old Content to be viewed, you probably need Random Post widget or plugin to show it. But why you use some plugin for some Simple work which you can get done inside WordPress easily

Just paste the below code were ever you want to display Random Posts :

<ul>
<?php
$args = array( 'numberposts' => 5, 'orderby' => 'rand', 'post_status' => 'publish', 'offset' => 1);
$rand_posts = get_posts( $args );
foreach( $rand_posts as $post ) : ?>
<li><h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2><p><?php the_excerpt(); ?>
</p></li>
<?php endforeach; ?>
</ul>

<ul> <?php $args = array( 'numberposts' => 5, 'orderby' => 'rand', 'post_status' => 'publish', 'offset' => 1); $rand_posts = get_posts( $args ); foreach( $rand_posts as $post ) : ?> <li><h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2><p><?php the_excerpt(); ?> </p></li> <?php endforeach; ?> </ul>

Now you will see the Random Posts, for more customization visit get_posts on WordPress Codex

Subscribe via Email

Share this:

  • Twitter
  • Facebook
  • Pocket
  • Print
  • Email

Related

November 26, 2012 Ritesh Sanap WordPress Hacks, How To, Random Posts, wordpress hacks

Post navigation

Previous Previous post: How to get Start Menu back in Windows 8
Next Next post: How to Load Web Page Faster using Prefetch and Prerender

Currently Trending

  • How to download Specific parts of YouTube videos
  • h4x0r ( Hacker ) - Blogger Template
  • You might also like this Widget for blogger or Related post widget
  • Windows Vista CD key
  • How to Hide Desktop Icons in Mac
  • How To Make Your Own Windows Media Player Theme
  • How to Increase Dropbox upload speed
  • HTTP2 Server Push for W3 Total Cache Minify plugin
  • How to Create Multiple Excerpts in WordPress
  • BlueStrap - WordPress Theme

Random Posts

Create Your Own Icons In Paint

February 29, 2008 By Ritesh Sanap Leave a Comment

How to Change the Welcome/Login Screen in Windows XP ?

August 30, 2008 By Ritesh Sanap 8 Comments

How to host javascript on blogger

June 21, 2010 By Ritesh Sanap 5 Comments

How to change Blogger Template without deleting widgets ?

March 9, 2009 By Ritesh Sanap Leave a Comment

Easy login URL

March 18, 2011 By Ritesh Sanap 2 Comments

WordPress

HTTP2 Server Push for W3 Total Cache Minify plugin

August 17, 2016 By Ritesh Sanap 5 Comments

How to Disable Emojis in WordPress

January 6, 2016 By Ritesh Sanap Leave a Comment

JetPack Related posts and Sharing not working with NGINX

November 10, 2015 By Ritesh Sanap Leave a Comment

Simply Pure – WordPress Theme

November 2, 2014 By Ritesh Sanap 2 Comments

Advanced What should we Write about next? – WordPress Plugin

July 28, 2014 By Ritesh Sanap Leave a Comment

How to Disable Self Pingback or TrackBack

January 16, 2014 By Ritesh Sanap Leave a Comment

BlueStrap – WordPress Theme

January 1, 2014 By Ritesh Sanap 15 Comments

How to Create Multiple Excerpts in WordPress

December 24, 2013 By Ritesh Sanap Leave a Comment

How to Disable Auto Update in WordPress

November 21, 2013 By Ritesh Sanap Leave a Comment

How to Delete Feedbacks from JetPack Contact Form

November 19, 2013 By Ritesh Sanap 9 Comments

Recent Posts

  • HTTP2 Server Push for W3 Total Cache Minify plugin
  • How to show hidden files and folders in Mac OS X
  • How to Disable Emojis in WordPress
  • Canva – Online Photo Editor
  • JetPack Related posts and Sharing not working with NGINX

Archives

Recommends

  • DigitalOcean – Cloud Hosting
  • Dropbox – Cloud Storage
  • Elegant Themes – WordPress Themes
  • LastPass – Password Manager
  • Like us on Facebook
  • Follow on Twitter
  • +1 on Google
  • Subscribe via Email
  • RSS Feed

© 2022 Best 2 Know · All Rights Reserved · We ♥ DigitalOcean

loading Cancel
Post was not sent - check your email addresses!
Email check failed, please try again
Sorry, your blog cannot share posts by email.