Page 1 of 1
php ad rotator
Posted: Thu Jan 14, 2016 7:01 pm
by Vegan
been slowly figuring how to convert old code to PHP
so far i have this function more or less looking right???
Code: Select all
<?php
$asin = array[];
array_push($asin, "B00UXTN5P0"); // GTX Titan X SC
// add more as needed
function showAISN($choice) {
$temp = '<iframe src="https://rcm-na.amazon-adsystem.com/e/cm?lt1=_blank&bc1=000000&IS2=1&bg1=FFFFFF&fc1=000000&lc1=0000FF&t=cpa07-20&o=1&p=8&l=as4&m=amazon&f=ifr&ref=ss_til&asins=';
$temp = $temp . $choice;
$temp = $temp . '" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe>';
echo($temp);
echo("\n");
?>
Re: php ad rotator
Posted: Thu Jan 14, 2016 8:43 pm
by Celauran
I suppose that works. I probably would have used a partial and just passed the variable into it.
Re: php ad rotator
Posted: Thu Jan 14, 2016 10:38 pm
by Christopher
Why call a function to add to the array? Are they coming from a datasource?
Code: Select all
$asin = array[];
array_push($asin, "B00UXTN5P0"); // GTX Titan X SC
// add more as needed
Why not just:
Code: Select all
$asin = array(
'B00UXTN5P0', // GTX Titan X SC
// add more as needed
);
I am confused how the the array above works with the function? Do you select a random item from the array and pass it to the function?
I'd rather see Presentation functions return a string that I can in turn insert into another template:
Code: Select all
function buildAISN($choice) {
$temp = '<iframe src="https://rcm-na.amazon-adsystem.com/e/cm?lt1=_blank&bc1=000000&IS2=1&bg1=FFFFFF&fc1=000000&lc1=0000FF&t=cpa07-20&o=1&p=8&l=as4&m=amazon&f=ifr&ref=ss_til&asins=';
$temp = $temp . $choice;
$temp = $temp . '" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe>';
return $temp . "\n";
}
$str = buildAISN($aisn[array_rand($aisn)]);
Creating a class might be even cleaner (and autoloadable). Plus you could add other optional settings as needed without changing the interface to build().
Code: Select all
class Aisn
{
private $ads;
private $width = 120;
private $height = 240;
function __construct($ads)
{
$this->ads = $ads;
}
function setSize($width, $height)
{
$this->width = $width;
$this->height = $height;
}
function build()
{
$temp = '<iframe src="https://rcm-na.amazon-adsystem.com/e/cm?lt1=_blank&bc1=000000&IS2=1&bg1=FFFFFF&fc1=000000&lc1=0000FF&t=cpa07-20&o=1&p=8&l=as4&m=amazon&f=ifr&ref=ss_til&asins=';
$temp .= $this->ads[array_rand($$this->ads)]);
$temp .= $temp . '" style="width:' . $this->width . 'px;height:' . $this->height . 'px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe>';
return $temp . "\n";
)
}
$ad = new Aisn($aisnStandard);
$str = $ad->build();
$ad = new Aisn($aisnLarge);
$ad->setSize(160, 600);
$str = $ad->build();
Re: php ad rotator
Posted: Sat Jan 16, 2016 7:45 am
by Vegan
the array is going to be used for a the rotator but I am not done with that yet
the rest is more just a conversion from how i was using javascript before
the idea was to use this PHP code as an alternative
I am not sure what all Amazon is doing with their new native ads, but this part of my code is more for a spot ad or 4 to fill white space etc
my code was intended to show a specific item, the randomized class looks useful for a swarm of randomized adds
clearly there is more to PHP to keep me puzzling away
Re: php ad rotator
Posted: Sun Jan 17, 2016 11:52 am
by Vegan
eventually I may modify the showAISN once I am able to figure out of it works with Amazon outside of the US
using my location function i can hopefully be more global in my offerings