Here is some simple PHP code to display and randomly position Ads.

Many blogs feature a block of sponsored ads. So every Ad gets equal fairness in terms of positioning on the page, it’s best to shuffle them around each time the page is refreshed.

Here is some code to achieve this:

<?php
$adsponsored = array (
<a href="/advertise.php"><img src="/images/ad1.png" alt="Ad1" /></a>’
,‘<a href="/advertise.php"><img src="/images/ad2.png" alt="Ad2" /></a>’,‘<a href="/advertise.php"><img src="/images/ad3.png" alt="Ad3" /></a>’,‘<a href="/advertise.php"><img src="/images/ad4.png" alt="Ad4" /></a>’);

//Display Ads sorted randomly
function sponsors(){
        global $adsponsored;
        shuffle( $adsponsored );
        echo join( "",$adsponsored );
}
?>

* please note that the tick marks have been altered to a different character.

In your HTML, include the code as follows:

<table><tbody>
<tr><?php sponsors(); ?></tr>
</tbody></table>
 

Here is an example page using the code: Ad Rotator Demo


Filed under: Tools by Andy