[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.


Closed Thread
 
LinkBack Thread Tools
Old 08-06-2008, 12:15 AM   #1 (permalink)
Senior Member
 
soggyindo's Avatar
 
Join Date: Feb 2008
Location: ✰✰✰Namehugger.com✰✰✰
Posts: 1,217
8.10 NP$ (Donate)

soggyindo is a splendid one to beholdsoggyindo is a splendid one to beholdsoggyindo is a splendid one to beholdsoggyindo is a splendid one to beholdsoggyindo is a splendid one to beholdsoggyindo is a splendid one to beholdsoggyindo is a splendid one to behold


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

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:
<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!

soggyindo is offline  
Old 08-08-2008, 04:35 PM   #2 (permalink)
NamePros Member
 
Join Date: May 2008
Posts: 124
0.00 NP$ (Donate)

hawkaw is a jewel in the roughhawkaw is a jewel in the roughhawkaw is a jewel in the rough


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
__________________
UAE Rush | BigMelt | AUStudies
hawkaw is offline  
Old 08-10-2008, 07:49 PM   #3 (permalink)
Senior Member
 
soggyindo's Avatar
 
Join Date: Feb 2008
Location: ✰✰✰Namehugger.com✰✰✰
Posts: 1,217
8.10 NP$ (Donate)

soggyindo is a splendid one to beholdsoggyindo is a splendid one to beholdsoggyindo is a splendid one to beholdsoggyindo is a splendid one to beholdsoggyindo is a splendid one to beholdsoggyindo is a splendid one to beholdsoggyindo is a splendid one to behold


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.
soggyindo is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 11:19 PM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85