How to Show a Random Post on the Homepage in WordPress

By default, WordPress displays all the posts on the homepage in reverse chronological order. This works out great for sites with continuously changing content like a news or technology blog. However, this leads to what I feel is a huge “wastage” of content that can still be relevant. Not all content is time sensitive. An outdated news story certainly doesn’t need to be resurfaced. But an interesting political analysis might always be relevant.
We’ve talked about republishing older blog posts before, and that’s one way to get leverage out of your existing content. But what if you could randomly serve up blog posts on your homepage everytime a visitor viewed it? There are lots of plugins and pieces of code that show you random blog posts on the sidebar in the form of a widget. But so far, I haven’t seen anything that displays a random blog post on the homepage.
I’m not looking to republish older blog posts, or replace the existing reverse chronological set up. I just want to show a random post on the homepage in WordPress above all the others, so that users are exposed to older content. These random posts can be selected from a pool of existing categories, or something else if necessary. But how do we go about this?

Appropriating Sticky Posts

There’s already an existing mechanism in WordPress for showing older posts above the default homepage. They’re called “sticky posts”. Basically whenever you create or edit a post, you can click the “Visibility” checkbox on the right hand side widget as shown here:
This will designate that particular post as “sticky”. What this means is that this post will display above all the others on the home page. It’s usually used for semi-permanent notices for example, where an admin wants to draw the reader’s attention to something important.
However, it occurred to me, that I can appropriate this mechanism to display random posts on a homepage. This way, I won’t need to mess around with styling, or modify the query, or perform any other kind of expensive operation. Here’s how I went about it.

Comments

Popular posts from this blog

Web Hosting Coupon Codes

Deadpool (2016)

How to Locate the PHP File Containing a Tag in WordPress