Random Ad Rotator for Glype

Posted by Vectro 16 November 2010

Some proxy webmasters use different ad networks instead of sticking solely to AdSense. Others use a combination of ad networks and sponsored banners. In these cases, it may be optimal to randomly rotate banner advertisements in Glype.

The code in this example has been tested for both static HTML banners and AdSense to work together in the same rotation.

First, create a file called ad_rotator.php and place the following code in it:

<?php
$random[] = 'Insert Ad Code Here';

$random[] = 'Insert Ad Code Here';

$i = rand(0, count($random)-1);

echo $random[$i];
?>

You will need to replace Insert Ad Code Here the ad with your own. This script does not have a limited number. You can add as many banners or as much random text as you wish by using $random[] = ''.

Here is a more specific example:

<?php
$random[] = '<a href="http://www.example.com/"><img 
src="http://www.exaple.com/banners/somebanner.gif" width="468" 
height="60" alt="Advertisement" border="0" /></a>';

$random[] = '<script type="text/javascript"><!--
google_ad_client = "ca-pub-0000000000000000";
/* big header unit */
google_ad_slot = "0000000000";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>';

$i = rand(0, count($random)-1);

echo $random[$i];
?>

This code will rotate 2 ads. One static HTML ad and one AdSense unit.

Make sure ad_rotator.php is placed in directory of the current theme the site uses. For example, if your Glype theme is called ‘mytheme’, this file would need to be placed in public_html/themes/mytheme.

The next thing to do is open your theme’s main.php file and find the spot where you want the ads to load. Place this code in that spot:

<?php include 'ad_rotator.php'; ?>

This tutorial is a modified version of the one found here. For some reason, the example on that site does not work when pasted directly into the main.php file of a Glype theme. That is why my example uses an include file.

Sorry, comments are closed.

Previous Post
«
Next Post
»