TinyPortal

Development => Block Codes => Topic started by: Adamzon on January 22, 2007, 12:44:34 PM

Title: Multiple banner ad rotator?
Post by: Adamzon on January 22, 2007, 12:44:34 PM
Hi!
Im need a script to rotate up to 10 lines/banners on my site www.glidarhoj.se
I have tried some diffrent scripts with include but i cant get it to work  :idiot2:

Do u have any idea?
www.glidarhoj.se


Title: Re: Multiple banner ad rotator?
Post by: Ianedres on January 22, 2007, 01:07:58 PM
Something I've used before...


<?php
$filename 
"path_to\oneliners.txt";
$handle fopen($filename"rb");
$contents fread($handlefilesize($filename));
fclose($handle);

$ads explode("\n"$contents);
$totalads count($ads)-1;
$i rand(0$totalads);

echo 
$ads[$i];
?>


In the filename 'oneliners.txt', just make sure you point the script to the proper path for it. Each line is read by the script on a random basis. You can even include valid HTML code within each line.
Title: Re: Multiple banner ad rotator?
Post by: JPDeni on January 22, 2007, 03:21:58 PM
Create a php block.

Put the following code in it, filling in the urls to your banners and links as needed, one per line:


$banners = array (
'<a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>',
'<a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>',
'<a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>',
'<a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>',
'<a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>',
'<a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>',
'<a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>',
'<a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>',
'<a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>',
'<a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>',
'<a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>'
);

shuffle($banners);

echo $banners[0];


It's easy to edit, you don't have to have any external files, and you can have as many or as few banners as you want.
Title: Re: Multiple banner ad rotator?
Post by: Adamzon on January 22, 2007, 05:19:06 PM
Great! But i need a multiple-line.

10 banners would be great

/Adam
Title: Re: Multiple banner ad rotator?
Post by: JPDeni on January 22, 2007, 05:43:39 PM
QuoteBut i need a multiple-line

Can you give me an example of what you need?
Title: Re: Multiple banner ad rotator?
Post by: TolerancE on January 22, 2007, 05:48:00 PM
FINALLY! I've been looking for this for what seems like forever.
Title: Re: Multiple banner ad rotator?
Post by: Adamzon on January 22, 2007, 05:51:10 PM
Look @ www.lidkopingsnytt.nu
in the right column (ads)
He has many diffrent ads, and they change places with every page open.

I have tried to inlude som diffrent php random banner generators but i cant get it to work :(
(in the big, all scripts that www.hotscripts.com has to offer in the randomize banner scripts)


/adam
Title: Re: Multiple banner ad rotator?
Post by: JPDeni on January 22, 2007, 05:59:51 PM
Oh. You want multiple banners. Well that's easy enough.

Keep the same code as I gave you above. Instead of


echo $banners[0];


use


$number_of_banners = 4; // put the number of banners you want to display here;

for ($i = 0; $i < $number_of_banners; ++$i)
  echo $banners[$i] , '<br />';
Title: Re: Multiple banner ad rotator?
Post by: Adamzon on January 22, 2007, 06:13:00 PM
OMG! U are wonderful!!! THANX!!

Is there anyway to specifie the width of the banners?

/Adam
Title: Re: Multiple banner ad rotator?
Post by: JPDeni on January 22, 2007, 06:14:44 PM
Just put the height and width in the img tags like you would put it in any other html img tags. There's nothing magical about them. :)

You're welcome. ;D
Title: Re: Multiple banner ad rotator?
Post by: alfie on January 23, 2007, 11:55:13 AM
that rocks jpdeni thank you
Title: Re: Multiple banner ad rotator?
Post by: Adamzon on January 23, 2007, 12:24:55 PM
U are great!
Thanx!

www.glidarhoj.se
Title: Re: Multiple banner ad rotator?
Post by: JPDeni on January 23, 2007, 02:12:46 PM
Cool.  8)

This will really work for anything. If you have a list of somethings and you want to display one or more of them randomly, this is the easiest way to do it. There are a couple of situations that you might want to get a little fancier, but this will work for most things.
Title: Re: Multiple banner ad rotator?
Post by: Inge Jones on January 25, 2007, 03:40:12 PM
This works great for my featured site links, thank you! :)
Title: Re: Multiple banner ad rotator?
Post by: Inge Jones on January 30, 2007, 12:13:19 PM
I am double posting as this is several days later and a new subject:

Is there any way to adapt this code so that I can use it to display random images from either my attachments or tp-dowloads folders?   I think my attempts are being blocked by the .htaccess of those directories, and I don't want to remove them really.  Any way round this?

My reason for wanting to use these folders is I wish my users to be able to update their images by themselves.
Title: Re: Multiple banner ad rotator?
Post by: IchBin on January 30, 2007, 04:00:22 PM
If you try to get around by changing the access with htaccess you're more than likely going to end up with people being able to access the downloads folder and download whatever they'd like. As its setup now, there's no direct linking allowed, for obvious reasons. Sounds to me like you need a custom download/upload download script to get what you want.
Title: Re: Multiple banner ad rotator?
Post by: Inge Jones on January 30, 2007, 04:07:03 PM
I have made a custom upload script which does work, but I don't really want the folder publicly accessible, only by someone running my script.   How does TP manage to get into its own tp-uploads folder with that .htaccess in place?
Title: Re: Multiple banner ad rotator?
Post by: insanemustang on May 08, 2007, 04:05:08 AM
Quote from: JPDeni on January 22, 2007, 03:21:58 PM
Create a php block.

Put the following code in it, filling in the urls to your banners and links as needed, one per line:


$banners = array (
'<a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>',
'<a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>',
'<a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>',
'<a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>',
'<a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>',
'<a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>',
'<a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>',
'<a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>',
'<a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>',
'<a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>',
'<a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>'
);

shuffle($banners);

echo $banners[0];


It's easy to edit, you don't have to have any external files, and you can have as many or as few banners as you want.

Just wanted to thank JPDeni, this code works great.
Title: Re: Multiple banner ad rotator?
Post by: FUBAR on May 15, 2007, 09:19:14 AM
The code is great but unfortunately it doesn't work with Firefox. 

Any suggestions?
Title: Re: Multiple banner ad rotator?
Post by: Zetan on May 15, 2007, 09:53:01 AM
The code works fine in Firefox on my site. It would have been mentioned before if it didn't.
Title: Re: Multiple banner ad rotator?
Post by: FUBAR on May 15, 2007, 11:55:16 AM
I apologize, I didn't remove the unneeded code for the extra banners and Firefox wasn't showing the red X for the missing images.  I removed the code and refreshed the page and it's working perfectly.

My mistake.  ;)
Title: Re: Multiple banner ad rotator?
Post by: Zetan on May 15, 2007, 12:28:10 PM
Pleased you fixed it  8)
Title: Re: Multiple banner ad rotator?
Post by: insanemustang on May 15, 2007, 04:19:36 PM
Works fine for my firefox too.  You may want to be sure you've got the newest firefox.
Title: Re: Multiple banner ad rotator?
Post by: Reality12 on May 21, 2007, 09:12:16 PM
This looks really good.

Is there a code you know to use HTML instead of PHP, for rotating banners?
Title: Re: Multiple banner ad rotator?
Post by: IchBin on May 21, 2007, 09:40:30 PM
html cannot achieve that. Either PHP or javascript is pretty much the only way.
Title: Re: Multiple banner ad rotator?
Post by: purplegold on May 26, 2007, 01:08:05 PM
$banners = array (
'<a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>',
'<a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>',
'<a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>',
'<a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>',
'<a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>',
'<a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>',
'<a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>',
'<a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>',
'<a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>',
'<a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>',
'<a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>'
);

shuffle($banners);

echo $banners[0];


Since I read that HTML cannot create such task, How can i input a text that shows up above all the random banners to work with php. also i would like to know how i can  centre the ads rather then showing up on the left.

Thanks alot!!! :laugh:
Title: Re: Multiple banner ad rotator?
Post by: Zetan on May 26, 2007, 01:43:12 PM
You can put anything between these:   '   '

$banners = array (
'<div align="center">Text Text Text<br><a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>More Text</div>',
'<div align="center">Text Text Text<br><a href="http://link/to/site" target="_blank">No Image, Text Link</a></div>',
'<div align="center">Text Text Text<br><a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>More Text</div>',
'<div align="center">Text Text Text<br><a href="http://link/to/site" target="_blank">No Image, Text Link</a></div>',
'<div align="center">Text Text Text<br><a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>More Text</div>',
'<div align="center">Text Text Text<br><a href="http://link/to/site" target="_blank">No Image, Text Link</a></div>',
);

shuffle($banners);


each banner or text entry needs to be centered

echo $banners[0];
Title: Re: Multiple banner ad rotator?
Post by: purplegold on May 26, 2007, 01:51:16 PM
Not quite, but thanks I kind of figured out something  :laugh:
Title: Re: Multiple banner ad rotator?
Post by: Zetan on May 26, 2007, 03:44:40 PM
Quote from: purplegold on May 26, 2007, 01:51:16 PM
Not quite, but thanks I kind of figured out something  :laugh:


All by yourself?... cool  8)
Title: Re: Multiple banner ad rotator?
Post by: ApplianceJunk on November 28, 2007, 11:57:49 PM
This code works great for us, thanks!

Quote from: ZTN on May 26, 2007, 01:43:12 PM
You can put anything between these:   '   '

$banners = array (
'<div align="center">Text Text Text<br><a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>More Text</div>',
'<div align="center">Text Text Text<br><a href="http://link/to/site" target="_blank">No Image, Text Link</a></div>',
'<div align="center">Text Text Text<br><a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>More Text</div>',
'<div align="center">Text Text Text<br><a href="http://link/to/site" target="_blank">No Image, Text Link</a></div>',
'<div align="center">Text Text Text<br><a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>More Text</div>',
'<div align="center">Text Text Text<br><a href="http://link/to/site" target="_blank">No Image, Text Link</a></div>',
);

shuffle($banners);


each banner or text entry needs to be centered

echo $banners[0];

How can I get a space at the top and bottom so the blocks do not look so close together?

With html I could use <br> or <p>

You can see how we use the code here.
ApplianceJunk Forums (http://appliancejunk.com/forums/index.php?action=forum)
It's the block on the left with the two CC ads.



Thanks,

Title: Re: Multiple banner ad rotator?
Post by: IchBin on November 29, 2007, 12:11:19 AM
You can add space by adding a < br /> (without the space after the "<"). Or you can add space to the div with the style attribute. Read up on CSS via google to figure that out using padding.
Title: Re: Multiple banner ad rotator?
Post by: xtremebass on December 08, 2007, 12:55:29 AM
This may sound stupid.. But
doesnt work in the php. I dont know the code for putting a horizontal line after each ad.  By the way, this code works great.
Title: Re: Multiple banner ad rotator?
Post by: katers on September 04, 2008, 05:27:12 PM
I am having a hard time figuring out how to add a space between banners as well if anyone can help.
Title: Re: Multiple banner ad rotator?
Post by: Mick on September 12, 2009, 04:36:30 PM
JP,

Im using your code in my test site:

http://chevyavalancheclub.com/cactestforum/index.php

You will see a 985x260px images.  I dont want my registered members to see this,....only guests.   What would be the code to add before your code?


$banners = array (
'<a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>',
'<a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>',
'<a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>',
'<a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>',
'<a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>',
'<a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>',
'<a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>',
'<a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>',
'<a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>',
'<a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>',
'<a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>'
);

shuffle($banners);

echo $banners[0];
Title: Re: Multiple banner ad rotator?
Post by: Lesmond on September 12, 2009, 05:00:30 PM
if its in a block, cant you just set the block for guest view only? but admin will still see it though
Title: Re: Multiple banner ad rotator?
Post by: Mick on September 12, 2009, 05:06:23 PM
Quote from: Lesmondâ„¢ on September 12, 2009, 05:00:30 PM
if its in a block, cant you just set the block for guest view only? but admin will still see it though

Its not in a block.   Its in the index.template.php
Title: Re: Multiple banner ad rotator?
Post by: Lesmond on September 12, 2009, 05:10:13 PM
ah sorry, thought it was a block, I should read more :idiot2:
Title: Re: Multiple banner ad rotator?
Post by: Mick on September 12, 2009, 05:15:27 PM
I figured it out.

I added:

global $user_info;

if ($user_info['is_guest'])


So now it looke like this:



global $user_info;

if ($user_info['is_guest'])

$banners = array (
'<a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>',
'<a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>',
'<a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>',
'<a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>',
'<a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>',
'<a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>',
'<a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>',
'<a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>',
'<a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>',
'<a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>',
'<a href="http://link/to/site" target="_blank"><img src="http://url/to/img"></a>'
);

shuffle($banners);

echo $banners[0];
Title: Re: Multiple banner ad rotator?
Post by: JPDeni on September 12, 2009, 07:22:47 PM
bluedevil, that's great. You got it worked out on your own. :up:

twister and extremebass, I'll need to know exactly what code you're using before I can figure out how to change it.
Title: Re: Multiple banner ad rotator?
Post by: Mick on September 12, 2009, 09:42:41 PM
Quote from: JPDeni on September 12, 2009, 07:22:47 PM
bluedevil, that's great. You got it worked out on your own. :up:

Yeah,i got to looking in the index.template and found it.   Surprisingly it worked with your code without adding other strings.

Im proud of myself...lol
Title: Re: Multiple banner ad rotator?
Post by: Mick on September 15, 2009, 03:25:31 PM
JP,  thanx again for this banner code.  Im diggin it!

Im using it to promote our club events ala myspace.

Our front page is what I call the "visitors" page.  Very limited on blocks.  Once logged in, the rest of the blocks and articles become visible and the huge banner dissapears.

Endless possibilities with TP.   I love it.

Thanx TP team for this excellent plugin for SMF.  Did i mention I use TP98?
Title: Re: Multiple banner ad rotator?
Post by: JPDeni on September 15, 2009, 04:54:12 PM
I'm so glad that you've been able to get TP to do what you need it to do. Once you start going, you're only limited by your imagination. I still use TP98 on my site, too.