Random Quotes

Came up with a fairly simple method to stick random quotes into Movable Type pages (requires PHP).

Music: Patti Smith :: blue poles


This method requires that your pages are parsed for PHP directives. If you don’t have PHP support, you should probably look for a JavaScript solution.

1) In the Templates section, create a new Index template called quotes.inc. In it, place one quote per line.

2) Put this code in your page template(s) where you wan the random quote to appear:

<?
// Select a random quote from an array

// On the next line, enter the full path on your web server
// to the generated quotes file.
// No need for any other changes to this code block.
$quotes = file(‘/full/path/to/quotes.inc’);

// Seed the random number generator
$somerand = srand ((float) microtime() * 10000000);

// How many quotes do we have to work with?
$num_quotes = sizeof($quotes);

// Choose a random number between 0 and the number of quotes in the array
$this_quote = rand(0,$num_quotes – 1);

// Now we have a random number to select from the array index, grab it.
$thisquote = $quotes[$this_quote];

// Spit it back
echo $thisquote;
?>

Also referenced here.

4 Replies to “Random Quotes”

  1. Pingback: half-pie

Leave a Reply

Your email address will not be published.