Dynadot โ€” .com Registration $8.99

The trick to make default Wordpress posts random posts? (Plugin for random WP posts)

Spaceship Spaceship
Watch

soggyindo

Established Member
Impact
79
Hi guys,
I had a search for this, and couldn't see anything. i hope someone can help, because it would be a great trick for a lot of us busy domainers!!

Basically, like most of us i have a few wordpress blogs - with original content - but don't have the time to update them every few days/week or month.

So that it won't look "stale" when someone returns, I'd like to display a random post - each time someone refreshes or goes to my site.

Ok - so I found a plugin that creates a link to a random post . It's called "Random Redrect" by Matt Mullenweg. It allows you to create a link (to yourblog.example.com/?random) which will redirect someone to a random post on your blog, in a StumbleUpon-like fashion.

Ok, so well and good. You just have to make a link to yourblog.example.com/?random to do this manually

Where I get stuck is making Wordpress's home page automatically "print" this post (rather than the latest post, or page you specify) (in your Settings > Reading options.)

The code I think controls it is in home.php

and it's the third line perhaps? (This is near the top)

<div id="content">

<div id="contentleft">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<h1><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h1>

Any clues as to achieve this miracle? I'd be very grateful if someone could help me out!

:tu:
 
1
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
.US domains.US domains
You can pull random posts from WordPress using the regular code, but by adding the parameter &orderby=rand to the function get_posts();

Example
Code:
<?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; ?>

By using this code, no additional plugins are required
 
1
•••
0
•••
Unstoppable Domains
Domain Recover
DomainEasy โ€” Payment Flexibility
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back