This article is part 1 of 2 of an article set I’ve named “Ghost Posts”. The inspriation behind the article set comes from something I read on Christopher’s post at astro-geek.com..
“If your Wordpress blog uses a home page or a landing page of some kind, featuring a random post on that page can serve a couple useful purposes. For one, it gives the reader an idea of what they can expect from your blog, especially if you make use of the Excerpt feature. Another benefit is that it helps keep your old archived posts visible. Normally people will only read the latest handful of posts, and ignore the rest. So this helps to open up the reader to even more of your valuable content.”
Well, after reading the post, I started to think more in-depth about the issue. He raised a very valid point that plagues the ‘blogger’. When our blog visitors come to our websites, they usually come with the intention of gathering new information, generally speaking. What seperates the blog from the website (yes, a blog is a website, but a different version of one. Some might even argue an evolution of a website altogether) is that the website, generally speaking once again, doesn’t house as much textual content. This gives a general website the ability to house most, if not all, of its tendrils in relatively little navigational space. For a general blogger, JungleJar for example, I would have to make some sort of navigational space on my index page with hundreds of links. Not only would this hog up much space, but this would also defeat the very purpose it was created to serve — getting our blog readers, new and old, reading past blog posts that have been scrolled away from the index page’s fresh content update area; with hundreds of links, especially with sometimes lengthy article titles, few would even bother searching the list. Why, you ask? Well, generally navigational links set up on an index page have no link pagination, and the font size used for said navigational links tends to be a bit smaller and can wear on the blog reader after a bit of scanning. So, for the blogger, an archival type system makes more sense.
So, what do you do? Well, Christopher and I (another Christopher), discussed the matter in a few emails. In this article we’ll be displaying a bit of Wordpress code to display random posts, one method of drawing attention to past posts that are now archived.
In the next article I’ll be discussing various strategies and methods of drawing attention to past posts. For now, this one is for the Wordpress users.
Random Posts In Wordpress Without Using Plugins
I’m sure the code snippet below will be familiar to all Wordpress users at some level or another. It begins the process of checking and displaying our posts.
1 | <?php while (have_posts()) : the_post(); ?> |
1 2 | <?php query_posts(array('orderby' => 'rand', 'category_name' => CategoryExample, 'showposts' == 10)) ?> <?php while (have_posts()) : the_post(); ?> |
In the code snippet above, just replace ‘CategoryExample’ with a category you’d like to display your random posts from. You can also change the number shown above after ’showposts’ to any number of random posts that you would like to display.
And, of course, to close the while loop you would just use endwhile as normal, seen below.
1 | <?php endwhile; ?> |
You can view an example of me using this exact code snippet in my ‘Design’ Category Listing.
Tips and Strategies To Keep Past Content Attracting Readers (Ghost Post Article 2/2)



Looking forward to the next part!
Thanks again
It was no problem. Thank you Christopher for the inspiration for the article set. The 2nd article should be online in a day or two. I’m sure the JungleJar readers will appreciate the methods and strategies of random post placement we discussed in our emails.
I’m just taking my time with the post at the moment to make sure I’ve got every logical post placement covered.
I’ve also got 4 wordpress tutorial videos that I still need to post to JungleJar that a loyal reader of the website contributed, and I’m struggling to find time just to watch them, heh.
Is there any way to make this work even if page caching is enabled? This is something that has got me puzzled.
awesome! thanks, this works perfect for me
Fantastic, I’m glad it worked for you.
Lyndi, how does page caching affect this for you?
Thank you
but some times , the showposts code have to be like this
’showposts’ => “10″
to work
Not sure why. I mean, that’s not really a ‘fix’ either. Did this happen to you more than once, or..?
Go into detail a bit if you don’t mind.
Interesting, I have to say. But can someone point to me some working website or blog that’s implementing this? I think even junglejar.com isn’t using this? Chris, are you using this on astro-geek?
I was using this for the /design category here at JungleJar.com, but this was before the re-design/re-development.
I can give you a good idea of what it looks like though..
Imagine a list of 10 links. The styling would be default of course unless you specified to use your own CSS classes.
As Ahmmad said, there is a little error in the code but it works nice… with some modification for me.
I had to put ‘cat’ => CategoryNumber for the category (‘category_name’ => CategoryExample did not work for me). And how to get more categories ? Or exclude some categories ?
You have to be careful that when you use the category name that you are using the actual name and not the category slug.
To change the number of categories displayed, just change the number ‘10′ in the code
’showposts’ == 10))
to whatever you’d like, and to exclude categories, Wordpress also has a built in query string for this. exclude=id, id, id
Just a minor typo that I noticed: ’showposts’ == 10 should be ’showposts’ => 10. Thanks for the post on this subject. It was a big help to a front-end guy like me.
It doesn’t really matter. It just comes down to preference with PHP markup and/or what’s considered more technically correct.
what if we want to display posts randomly from all cats instead to point any partucular one.
For 13 years she has been an invalid. ,