Random Content Plugin
This plugin retrieves a random post/page/either one of them from your WordPress installation, used in much the same way as the get_posts()
WordPress function. The plugin was based off from Gruppo Modulo’s Random Subpages plugin but extended because I needed much more than subpages.
Installation
- Download the plugin here.
- Unzip it somewhere.
- Upload
ind_random_content.php
into yourwp-content/plugins
directory. - Go to your WordPress Admin Panel > Plugins and activate the plugin.
Usage
To use the plugin to show a random post and/or page, you should open up your template file and use the following function:
ind_get_random_content( $arguments );
Possible arguments are:
- show (string)
- show only posts, or pages, or both
- possible values:
post
|page
|all
|both
- numberposts (integer)
- number of posts/pages to return
- parentpage (integer)
- limits returned pages to subpages of parentpage
- categories (integers, separated by commas)
- limits returned posts to posts filed under categories found in arguments
- exclude (integers, separated by commas)
- limits returned posts to posts NOT filed under categories found in arguments
Sample Usage
To use the plugin to get and show one random post from categories with IDs 3, 4, and 5:
<?php
$myposts = ind_get_random_content( 'show=post&numberposts=1&categories=3,4,5' );
foreach( $myposts as $post ) {
setup_postdata( $post );
?>
<h1></h1>
<p><?php the_content(); ?></p>
<?php
}
?>
Neil Graver
I found this plug in after searching around for ages for a ‘proper’ random posts plugin for wordpress that actually shows the content of the post, so extremely good work for developing one.
However, I can’t get it working as I believe wordpress 2.3 doesn’t have the post2cat tables called in the plugin code. I tried fiddling around with it, but getting it working is far beyond my capabilities.
Do you have any plans to release an update?
Thanks
Angela
Hi Neil,
Thanks for your interest in the plugin! I actually am currently working on an update, so you can expect to see it around sometime after the holidays probably, when I can sit back down and finish the update :)
Hjalle
There is a bug where unpublished posts shows up. Add this to the query-string before “GROUP BY” to fix the issue:
and post_status = ‘publish’
Karl
Hi Angela,
Many thanks for the plugin, I’d been searching for ages for a plugin to randomly display a subpage. Gruppo Modulo’s plugin didn’t work for me on WP 2.7, but yours did and it’s working great – thanks again!