|
Joined: Oct 2008
Posts: 104
Member
|
Member
Joined: Oct 2008
Posts: 104 |
I use the custom islands to post advertising on our forums. One of our clients wants to randomly rotate 3 ads. I found a nice/simple php script to do the job. But... I'm not sure where to put the code to call the include (or the file containing the script). I need to use this code to call in the script with the rotating ads... <? include_once("AdRotation.php"); echo "<div align='center'>$bannerAd</div>"; ?> And I need to make sure AdRotation.php resides in the right place to be called into the custom island. Figured it was better to ask then to break things :-) You can see it in action here (a test page I set up)... http://www.pianoworld.com/RotateAdTest.phpEach time the page is reloaded, it randomly displays one of three ads.
|
|
|
|
Joined: Dec 2003
Posts: 6,633 Likes: 85
|
Joined: Dec 2003
Posts: 6,633 Likes: 85 |
Okay for starters you can visit the faqs how do I forums here. But basically you do not paste the <? or closing ?> in the php area in the island. It is already done by the script.
Blue Man Group There is no such thing as stupid questions. Just stupid answers
|
|
|
|
Joined: Oct 2008
Posts: 104
Member
|
Member
Joined: Oct 2008
Posts: 104 |
Great, thanks Ruben.
Headed for the FAQ now.
|
|
|
|
Joined: Oct 2008
Posts: 104
Member
|
Member
Joined: Oct 2008
Posts: 104 |
Ok, so I read the tips.
It looks like I would need to put the entire php script into the section ...
/* PHP CODE HERE, IF NECESSARY */
--- Long PHP Script HERE with no opening/closing php tags ---
/* DO NOT CHANGE THE LINE BELOW */
Then call the script in here, something like this...
$body = <<<EOF
<div align='center'>$bannerAd</div>
EOF; /* DO NOT CHANGE THE LINE ABOVE */
Am I understanding this correctly?
|
|
|
|
Joined: Dec 2003
Posts: 6,633 Likes: 85
|
Joined: Dec 2003
Posts: 6,633 Likes: 85 |
Yea but you need to declare the value in the PHP section of the island. Then place the value in the eof section to display it. So the php section will have $bannerAd= Then the eof section will have $bannerAd
Blue Man Group There is no such thing as stupid questions. Just stupid answers
|
|
|
|
Joined: Dec 2003
Posts: 6,633 Likes: 85
|
Joined: Dec 2003
Posts: 6,633 Likes: 85 |
Not knowing the banner script. I believe you need to delete the echo statement in the php section of the island also.
Blue Man Group There is no such thing as stupid questions. Just stupid answers
|
|
|
|
Joined: Oct 2008
Posts: 104
Member
|
Member
Joined: Oct 2008
Posts: 104 |
It seems to work fine in the main part of our site, but when I put it into the island, it only pulls in the first banner in the list (as though it's not parsing through?).
Here is the entire code, including the Never Remove stuff for the ubb:
/* PHP CODE HERE, IF NECESSARY */
$bannerCounter= 1;
$bannerCode[$bannerCounter] = "<OBJECT classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0' width=\"125\" height=\"125\"> <param name='movie' value=\"http://www.m-audio.com/images/web/pianoworld_banners/125x125_1.swf\"> <param name='quality' value=\"high\"> <param name='bgcolor' value='#FFFFFF'> <param name='loop' value=\"false\"> <EMBED src=\"http://www.m-audio.com/images/web/pianoworld_banners/125x125_1.swf\" quality='high' bgcolor='#FFFFFF' width=\"125\" height=\"125\" loop=\"false\" type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash'> </EMBED> </OBJECT></a>";
$bannerCounter++;
$bannerCode[$bannerCounter] = "<OBJECT classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0' width=\"125\" height=\"125\"> <param name='movie' value=\"http://www.m-audio.com/images/web/pianoworld_banners/125x125_2.swf\"> <param name='quality' value=\"high\"> <param name='bgcolor' value='#FFFFFF'> <param name='loop' value=\"false\"> <EMBED src=\"http://www.m-audio.com/images/web/pianoworld_banners/125x125_2.swf\" quality='high' bgcolor='#FFFFFF' width=\"125\" height=\"125\" loop=\"false\" type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash'> </EMBED> </OBJECT></a>";
$bannerCounter++;
$bannerCode[$bannerCounter] = "<OBJECT classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0' width=\"125\" height=\"125\"> <param name='movie' value=\"http://www.m-audio.com/images/web/pianoworld_banners/125x125_3.swf\"> <param name='quality' value=\"high\"> <param name='bgcolor' value='#FFFFFF'> <param name='loop' value=\"false\"> <EMBED src=\"http://www.m-audio.com/images/web/pianoworld_banners/125x125_3.swf\" quality='high' bgcolor='#FFFFFF' width=\"125\" height=\"125\" loop=\"false\" type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash'> </EMBED> </OBJECT></a>"; $bannerCounter++;
$bannerAdTotals = $bannerCounter - 1; if($bannerAdTotals>1) { mt_srand((double)microtime() * 1234567); $bannerPicked = mt_rand(1, $bannerAdTotals); } else { $bannerPicked = 1; } $bannerAd = $bannerCode[$bannerPicked];
/* DO NOT CHANGE THE LINE BELOW */ $body = <<<EOF
<div align='center'>$bannerAd</div>
EOF; /* DO NOT CHANGE THE LINE ABOVE */
|
|
|
|
Joined: Jun 2006
Posts: 16,372 Likes: 129
|
Joined: Jun 2006
Posts: 16,372 Likes: 129 |
Well, the islands are cached; so it's possible it's just caching the output of it running once... Your best bet is having all that code in a php file and using an include() to include it in the custom island.
|
|
|
|
Joined: Oct 2008
Posts: 104
Member
|
Member
Joined: Oct 2008
Posts: 104 |
Thanks Gizmo,
I do have it all in a file called AdRotation.php The file is in the forum/ directory.
I don't know the correct syntax to pull it in though.
In a standard .php page it would be like this (but this doesn't work).
/* PHP CODE HERE, IF NECESSARY */
/* DO NOT CHANGE THE LINE BELOW */ $body = <<<EOF
<? include_once("AdRotation.php"); echo "<div align='center'>$bannerAd</div>"; ?>
EOF; /* DO NOT CHANGE THE LINE ABOVE */
|
|
|
|
Joined: Jun 2006
Posts: 1,344
veteran
|
veteran
Joined: Jun 2006
Posts: 1,344 |
This is what I do for my portal box and for ad island and it works /* PHP CODE HERE */ $body = <<<EOF <center> <? php include("http://path_to/AdRotation.php"); ?> </center> EOF;
|
|
|
|
Joined: Jun 2006
Posts: 16,372 Likes: 129
|
Joined: Jun 2006
Posts: 16,372 Likes: 129 |
I THINK:
/* PHP CODE HERE, IF NECESSARY */
include_once("AdRotation.php");
/* DO NOT CHANGE THE LINE BELOW */
$body = <<<EOF
<div align="center">$bannerAd</div>
EOF;
/* DO NOT CHANGE THE LINE ABOVE */
If you store the php file outside of the cache_builders/custom folder you'd need to just link to its path on the server in the include statement, ex: /home/yoursite/public_html/forums/AdRotation.php
|
|
|
|
Joined: Oct 2008
Posts: 104
Member
|
Member
Joined: Oct 2008
Posts: 104 |
The only way I could seem to get it to work was put the full code back in the php section, call it in the $body, and set the cache for that custom island to 1 minute.
At least now it calls random ads after one minute.
|
|
|
1 members (mavorg),
180
guests, and
112
robots. |
Key:
Admin,
Global Mod,
Mod
|
|
|
|