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
Something I've used before...
<?php
$filename = "path_to\oneliners.txt";
$handle = fopen($filename, "rb");
$contents = fread($handle, filesize($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.
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.
Great! But i need a multiple-line.
10 banners would be great
/Adam
QuoteBut i need a multiple-line
Can you give me an example of what you need?
FINALLY! I've been looking for this for what seems like forever.
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
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 />';
OMG! U are wonderful!!! THANX!!
Is there anyway to specifie the width of the banners?
/Adam
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
that rocks jpdeni thank you
U are great!
Thanx!
www.glidarhoj.se
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.
This works great for my featured site links, thank you! :)
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.
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.
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?
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.
The code is great but unfortunately it doesn't work with Firefox.
Any suggestions?
The code works fine in Firefox on my site. It would have been mentioned before if it didn't.
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. ;)
Pleased you fixed it 8)
Works fine for my firefox too. You may want to be sure you've got the newest firefox.
This looks really good.
Is there a code you know to use HTML instead of PHP, for rotating banners?
html cannot achieve that. Either PHP or javascript is pretty much the only way.
$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:
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];
Not quite, but thanks I kind of figured out something :laugh:
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)
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,
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.
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.
I am having a hard time figuring out how to add a space between banners as well if anyone can help.
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];
if its in a block, cant you just set the block for guest view only? but admin will still see it though
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
ah sorry, thought it was a block, I should read more :idiot2:
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];
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.
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
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?
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.