This is a little snippet of code I’ve been using since forever now. It is a simple way of putting quotes, or any other data you want, on your site and having it rotate randomly through the different items you specify. I’ve used this in a bunch of different ways and it has thus far not failed. Not sure where I found it though, as it’s been so long.
The download (here) has three files, but you only really need two.
- The first you need to edit is randomquote.php, it has comments in it to identify what you need to change, but the short of it is you need to edit the web server path to where your files are stored. The only other thing you need to edit here is to set $random to false if you want quotes to be displayed sequentially.
- Next add your quotes to the randomquote.inc, or if you want to have them sequentially displayquote.inc. Make sure the quote is on one line, no wrapping, and don’t leave a blank line.
- Now to place the random quote in your php file
On my own site I use it to display client quotes in the footer as well as the right bar on the homepage. I put the random quote include inside a div styled for the area it’s in, and it displays it in both sections without having to have two separate quote scripts running.
On a recent clients site I used it to bring up quotes, but each quote had to have different styling. So I included the div and other tags in the quote file itself for each quote.
And on another site I used it to randomly rotate an entire header along with random graphics. So you should be able to find this useful in any application with a bit of cleverness.