| |||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | #1 (permalink) | |
| Senior Member | 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) Quote:
| |
| |
| | #2 (permalink) |
| NamePros Member | 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; ?>
|
| |
| | #3 (permalink) |
| Senior Member | you are a superstar - i'll give it a try and let everyone know how i go on these sites Skateboard Logos Vegetarian Recipes Contemporary Art Gallery Artists Websites Rock Songwriting World Religions Psychic Buddhism Meditation Techniques Cure For Depression Bipolar Disorder Short Quotes Ayurveda Treatment Mental Health The Liver Computer Addiction rep added!
__________________ Last edited by soggyindo; 12-11-2008 at 05:55 PM. |
| |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| |