How to put a random post on your Wordpress blog
How to put a random post or excerpt on your Wordpress blog? That was the question, which crossed my mind yesterday. Thanks to Google, that I've found the method on Wordpress forum. It is just simple. What you need to do is paste the code below on your theme files. In this blog, I put the random excerpt on the top right, so that it is easy to be noticed.
-
<?php
-
$rand_id = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_status = 'publish' ORDER BY RAND() LIMIT 1");
-
query_posts("p=$rand_id");
-
?>
-
<?php while (have_posts()) : the_post(); ?>
-
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a>
-
<?php the_excerpt(); ?>
-
<br /><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">Read more...</a>
-
<?php endwhile; ?>
< ?php the_excerpt(); ?> can be changed to < ?php the_content(); ?> if you want to display the full post instead of the excerpt.
If you dont want to mess with this code, you have another choice to use Wordpress plugins from wasabi, Random Posts and Random Excerpts. According to the author, you can limit the length of the excerpt generated, which cannot be done by the code above.
But I don't use the plugins. Doing something without plugins is better for me because I can learn while applying the code. Not just knowing how to activate or deactivate something. But it is your choice by the way
Related links:
Old posts. Don’t throw them away. Why?
Templates Tags - Post tags at Wordpress Codex
Probably related entries:
- Wordpress 2.0.7 is fresh from the fridge After ten days after the release of Wordpress 2.0.6, Wordpress comes with the new fixed version of 2.0.6.
- Blogging in a blog community is a very good start for beginners If you want to earn money by blogging, traffic is the most important thing. Here I will share
- How to make a photoblog using Wordpress Combining photo blog with the most popular blog engine is a brilliant idea. Maybe you are already tired
- Get your Wordpress.com Wordpress.com is free blog based on the latest alpha of Wordpress 1.6 which has a new dashboard, WYSIWYG post
- Fadtastic - A bright and fluid 3-column theme I've came across this Wordpress theme at my Wordpress.com blog. Fadtastic is a clean Wordpress theme by Andrew
Make A Comment: ( 8 so far )
8 Responses to “How to put a random post on your Wordpress blog”
thanks for the linkback. the random post plugin is really useful. it digg up all your old posts to in front.
CypherHackz
January 4th, 2007
Thanks for the good link
WebTrafficMan
January 5th, 2007
Thanks for the good link. Great plugin
WebTrafficMan
January 5th, 2007
yg related post nie lak cam ne?
aman
January 7th, 2007
We can do that in blogger? I like to know.
Prismatico
January 19th, 2007

















