TinyPortal

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

Title: Multiple banner ad rotator?
Post by: Adamzon on January 22, 2007, 05:44:34 AM
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, 06:07:58 AM
Something I've used before...

Code: [Select]
<?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, 08:21:58 AM
Create a php block.

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

Code: [Select]
$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, 10:19:06 AM
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, 10:43:39 AM
Quote
But 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, 10:48:00 AM
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, 10:51:10 AM
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, 10:59:51 AM
Oh. You want multiple banners. Well that's easy enough.

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

Code: [Select]
echo $banners[0];

use

Code: [Select]
$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, 11:13:00 AM
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, 11:14:44 AM
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, 04:55:13 AM
that rocks jpdeni thank you
Title: Re: Multiple banner ad rotator?
Post by: Adamzon on January 23, 2007, 05:24:55 AM
U are great!
Thanx!

www.glidarhoj.se
Title: Re: Multiple banner ad rotator?
Post by: JPDeni on January 23, 2007, 07:12:46 AM
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, 08:40:12 AM
This works great for my featured site links, thank you! :)
Title: Re: Multiple banner ad rotator?
Post by: Inge Jones on January 30, 2007, 05:13:19 AM
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, 09:00:22 AM
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, 09:07:03 AM
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 07, 2007, 09:05:08 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:

Code: [Select]
$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, 02: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, 02: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, 04: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, 05:28:10 AM
Pleased you fixed it  8)
Title: Re: Multiple banner ad rotator?
Post by: insanemustang on May 15, 2007, 09:19:36 AM
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, 02: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, 02: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, 06:08:05 AM
Code: [Select]
$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, 06:43:12 AM
You can put anything between these:   '   '
Code: [Select]
$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, 06:51:16 AM
Not quite, but thanks I kind of figured out something  :laugh:
Title: Re: Multiple banner ad rotator?
Post by: Zetan on May 26, 2007, 08:44:40 AM
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, 04:57:49 PM
This code works great for us, thanks!

You can put anything between these:   '   '
Code: [Select]
$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
Code: [Select]
<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 28, 2007, 05:11:19 PM
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 07, 2007, 05:55:29 PM
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, 10:27:12 AM
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, 09:36:30 AM
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?


Code: [Select]
$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, 10:00:30 AM
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, 10:06:23 AM
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, 10:10:13 AM
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, 10:15:27 AM
I figured it out.

I added:

Code: [Select]
global $user_info;

if ($user_info['is_guest'])

So now it looke like this:

Code: [Select]

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, 12: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, 02:42:41 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, 08:25:31 AM
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, 09:54:12 AM
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.