A little PHP script to rotate ads, text snippets, images, web pages, links or anything else that you want to rotate randomly. Affectionately called Randy, the Randy script reads an external file, picks a few random lines from it then inserts them into a web page at the point where randy.php is called for use. This was initially written to display text ads in random order but can easily display any HTML content.
I’ve used Randy to display
- random hyperlinks
- random images in a gallery
- random tube clips
- random user reviews
- random ads
- random text snippets
- and more…
- Random display of data stored within a data file
- Display of mapped companion data alongside the data chosen randomly from the primary input data file.
- Data is displayed within an HTML table.
- The number of columns to display the data within can be configured
- The number of data items to retrieve can be configured
- Per item CSS classes e.g. class=”randy-1″ and class=”randy-companion-1″
- Randy os easy to use.
- Download the script (randy.php)
- Upload it to your server
- Unzip it
- Enter the Randy directory and edit the configs in randy.php
- Add data to data.txt
- Add data to companion.txt (optional)
- Call the script into your web page
When editing data.txt, put each item of data on its own line within. There must be no empty lines. You can use HTML if you want to.
For example, to display three ads within <div> tags with inline CSS you would enter markup like this into ads.txt:
<div style="margin-left: auto; margin-right: auto; text-align: center;"><img src="http://placehold.it/140x100" /><br /><a href="#"><strong>One</strong></a></div> <div style="margin-left: auto; margin-right: auto; text-align: center;"><img src="http://placehold.it/140x100" /><br /><a href="#"><strong>Two</strong></a></div> <div style="margin-left: auto; margin-right: auto; text-align: center;"><img src="http://placehold.it/140x100" /><br /><a href="#"><strong>Three</strong></a></div>
Call the script into pages with either a PHP include or a server side include.
Server side include:
Configure the following variables in randy.php:
- $title — the title to display with ads (optional)
- $file — the file that contains the ads or data to display randomly
- $pre — anything that should display before any random data is displayed (optional)
- $post — anything that should display after any random data is displayed (optional)
- $infix — anything that should display between each randomly displayed item (optional)
- $show — maximum number of items to display
- $per_row — data can be displayed in columns. Use this to specify the number of items to display per row. This is the same as setting a column count.
Randy has three advanced settings:
- $companion — this is for specifying a file containing companion data to display alongside the main file data
- $infill — specifies the data to use when the companion file has fewer lines of data than the primary file. can be set to ‘use item count’ if you want to display each item’s row placement number within the data.txt file.
- $dpath — this is for specifying a directory path to the data files if they placed within a sub directory of Randy.
The companion file is optional.