Get Random Post in wordpress
Sometimes we want to display random post in wordpress. So How do I show random post on wordpress. Copy following code above and snippet to your wordpress theme file:
<?php query_posts(’orderby=rand&showposts=5?); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<h1>
<a href=”<?php the_permalink(); ?>” title=”<?php the_title(); ?>”><?php the_title(); ?></a>
</h1>
<?php the_content(); ?>
<?php endwhile; ?>
<?php endif; ?>
You can snippet code above in your wordpress theme anywhere, in Index, sidebar or on other pages. You can change showposts = 5 with a number up to how many posts are you want to show in random.
You can also add a category-id parameter if only want to display a certain category, for instance cat =1
And for the_content () Can you replace with the_excerpt () if you just want to show the excerpt only.
It’s so easy to show random post in wordpress. Good luck and have a nice blogging
Awesome blog! Google Adsense is an awesome source of income for webmasters, Thanks for the post.Eddiehttp://www.postlinksongoogle.com