MyBB Community Forums

Full Version: google ads on rotation
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
On my site aclubbers guide.net (without the space) im trying to set up some adsense on a rotation between me and my partners code so that its 50/50.

The code im using is:
<?php
$a='<script type="text/javascript"><!--
google_ad_client = "pub-5768";
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = "728x90_as";
google_ad_type = "text";
google_ad_channel = "";
google_color_border = "666666";
google_color_bg = "666666";
google_color_link = "ffffff";
google_color_text = "ffffff";
google_color_url = "f29935";
//-->

</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>';


$b='<script type="text/javascript"><!--
google_ad_client = "pub-9104";
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = "728x90_as";
google_ad_type = "text";
google_ad_channel = "";
google_color_border = "666666";
google_color_bg = "666666";
google_color_link = "ffffff";
google_color_text = "ffffff";
google_color_url = "f29935";
//-->

</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>';


$var = rand(1,2);

if ($var==1) { 
echo $a;
} 
else {
echo $b; 
}
?>
However Its not working properly. Ive put a screenprint below so you can see the problem. Any help would be appreciated.

[/code]
How are you adding the code to your forum? I'm guessing the php code is not executed.
the code above is being placed in the header file - is that what you meant?
you can't use php in a template ... put it in your global.php and add {$vars} in your headertemplate
Yeah, but I think you need to do eval() or something, else the code will not be executed.

EDIT: LeX-'s way will probably work.
oooOOoo that seems a little complicated, are there any tutorials or could you show me?
Put the php code in your global.php after
// Run global_start plugin hook now that the basics are set up
$plugins->run_hooks("global_start");

$a='<script type="text/javascript"><!--
google_ad_client = "pub-5768";
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = "728x90_as";
google_ad_type = "text";
google_ad_channel = "";
google_color_border = "666666";
google_color_bg = "666666";
google_color_link = "ffffff";
google_color_text = "ffffff";
google_color_url = "f29935";
//-->

</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>';


$b='<script type="text/javascript"><!--
google_ad_client = "pub-9104";
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = "728x90_as";
google_ad_type = "text";
google_ad_channel = "";
google_color_border = "666666";
google_color_bg = "666666";
google_color_link = "ffffff";
google_color_text = "ffffff";
google_color_url = "f29935";
//-->

</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>';


$var = rand(1,2);

if ($var==1) { 
 $add = $a;
} 
else {
 $add =  $b; 
}

Then open your header template and add {$add} where you want the ads to be displayed. I suggest add it just before <navigation>.
Lex your a legend, thanks for your help it worked perfectly, this has taken me a week ad youve sorted it in less than an hour, i really appreciate it
Great detail & thanks a lot Lex Big Grin