SimplePortal

Customization => Blocks and Modifications => Block Requests => Topic started by: shawn on October 08, 2012, 12:59:54 PM

Title: Banner Rotation
Post by: shawn on October 08, 2012, 12:59:54 PM
Hey all,

Is there an easy way to use the PHP block to add a banner rotation for advertising? I want to add 2 banners to rotate during each page view on a header block.
Title: Re: Banner Rotation
Post by: phantomm on October 08, 2012, 01:41:01 PM
Try this:
Code: [Select]
function RandomCode ($array)
{
  $total = count($array);
  $call = rand(0,$total-1);
  return $array[$call];
}

$html = array (
  '<a href="#">Link1</a>',
  '<a href="#">Link2</a>'
);

echo ''.RandomCode($html).'';

I found this on my FTP, works nice :)

Replace <a href="#">Link1</a> and <a href="#">Link2</a> with your HTML code.
Title: Re: Banner Rotation
Post by: shawn on October 08, 2012, 02:21:48 PM
phantomm, thank you VERY much! That worked perfectly. :)
Title: Re: Banner Rotation
Post by: silvershark on October 12, 2012, 11:07:34 AM
ok...I am so new at this stuff! My site has been live for almost two weeks and I am learning as I go. So my question is, where do you enter that code and what do you need to do to make it function
Title: Re: Banner Rotation
Post by: AngelinaBelle on October 12, 2012, 11:18:34 AM
That is php code.  so you would put that in a custom php block.
But that code is not complete. Link1 and Link2 would probably be replaced by your desired image banner, and you would need to replace the "#" with the actual URL you want the link to go to.

Title: Re: Banner Rotation
Post by: silvershark on October 12, 2012, 11:32:20 AM
OK so I applied the code. But how do I add images instead of just text with a link to the image. I suppose image tags of some sort but where do I put them. It works, but it only displays text that can be clicked on
Title: Re: Banner Rotation
Post by: phantomm on October 12, 2012, 11:36:54 AM
use
Code: [Select]

function RandomCode ($array)
{
  $total = count($array);
  $call = rand(0,$total-1);
  return $array[$call];
}

$html = array (
  '<a href="#"><img src="URL_TO_IMAGE" alt="" /></a>',
  '<a href="#"><img src="URL_TO_IMAGE" alt="" /></a>'
);

echo ''.RandomCode($html).'';
Title: Re: Banner Rotation
Post by: silvershark on October 13, 2012, 12:51:09 AM
use
Code: [Select]

function RandomCode ($array)
{
  $total = count($array);
  $call = rand(0,$total-1);
  return $array[$call];
}

$html = array (
  '<a href="#"><img src="URL_TO_IMAGE" alt="" /></a>',
  '<a href="#"><img src="URL_TO_IMAGE" alt="" /></a>'
);

echo ''.RandomCode($html).'';

Thank you. Works great!
Title: Re: Banner Rotation
Post by: Wishmaster on November 23, 2012, 03:01:13 PM
Hello,

If i want this to <p align="center"> how do i then do that ?

Brian
Title: Re: Banner Rotation
Post by: phantomm on November 23, 2012, 04:09:17 PM
Code: (Find) [Select]
echo ''.RandomCode($html).'';
Code: (Replace with) [Select]
echo '<p align="center">'.RandomCode($html).'</p>';
Title: Re: Banner Rotation
Post by: Wishmaster on November 23, 2012, 04:38:03 PM
Thanks that looks way better  ;D
SimplePortal 2.3.8 © 2008-2024, SimplePortal