Azharkamar.com

How to Display a List of Random Post Titles in WordPress

Tutorials
12 Apr 2010
Comment

A list of random post titles! Yeah, sometimes displaying random posts in your WordPress blog might be good. There’s a few tutorials lurking out there in the web but some aren’t really quite comprehensive and straight forward. So, I’ll do the best I can here.

I’ll tell you exactly what you want to know – How to display a list of random post titles in WordPress. So how do you go about doing so? It’s very simple actually. Only requires a few lines of PHP codes. It’s quite flexible too, in the sense that you can choose how many post titles you want displayed.

Displaying Random Post Titles

So how do you do it? Simple. Add this piece of code into your template.

<li>
<ul>
<?php $rand_posts = get_posts('numberposts=5&orderby=rand');
foreach($rand_posts as $post) : ?>
<li>
<a href = "<?php the_permalink(); ?>">
<? php the_title(); ?>
</a>
</li>
<?php endforeach; ?>
</ul>
</li>

Well that’s it. Now go and have a good time trying it out!

Tags -
Author - Azhar Kamar

Write a Comment! NOW! :)

Current ye@r *