SimplePortal
Customization => Blocks and Modifications => Block Requests => Topic started by: Verso on April 21, 2009, 04:06:36 AM
-
I am looking for a block that will show a random banner.
Any helpers?
-
That should be easy to do with a PHP block. Below is some example code that you could use.
$banners = array(
'http://au.php.net/images/php.gif',
'',
'',
);
echo '<img src="', $banners[rand(0, count($banners) - 1)], '" alt="" />';
The banners array can hold a list of images (banners) that will be shown randomly.
-
Thanks for your input but my coding knowledge is next to nothing......
The 3 logos I would like to be included are:-
http://www.suffolksportsforum/forumimages/fss.jpg
http://www.suffolksportsforum/forumimages/coastal.jpg
http://www.suffolksportsforum/forumimages/premier.gif
Could you amend the code for me please?
-
$banners = array(
'http://www.suffolksportsforum.com/forumimages/fss.jpg',
'http://www.suffolksportsforum.com/forumimages/coastal.jpg',
'http://www.suffolksportsforum.com/forumimages/premier.gif',
);
echo '<img src="', $banners[rand(0, count($banners) - 1)], '" alt="" />';
-
Sorry to be a nuisance but the block just appears empty
-
That's because you forgot the .co.uk on every one of those images. Here's what you need:
$banners = array(
'http://www.suffolksportsforum.co.uk/forumimages/fss.jpg',
'http://www.suffolksportsforum.co.uk/forumimages/coastal.jpg',
'http://www.suffolksportsforum.co.uk/forumimages/premier.gif',
);
echo '<img src="', $banners[rand(0, count($banners) - 1)], '" alt="" />';
-
That's because you forgot the .co.uk on every one of those images. Here's what you need:
$banners = array(
'http://www.suffolksportsforum.co.uk/forumimages/fss.jpg',
'http://www.suffolksportsforum.co.uk/forumimages/coastal.jpg',
'http://www.suffolksportsforum.co.uk/forumimages/premier.gif',
);
echo '<img src="', $banners[rand(0, count($banners) - 1)], '" alt="" />';
[/quote
How silly do I feel! putting .com instead of .co.uk!!!!
Thanks to both of you for your help - One last thing, can I add hyperlinks to the banners? and how..........
-
That should be easy, if you want the same link for every banner then use this code:
$banners = array(
'http://www.suffolksportsforum.co.uk/forumimages/fss.jpg',
'http://www.suffolksportsforum.co.uk/forumimages/coastal.jpg',
'http://www.suffolksportsforum.co.uk/forumimages/premier.gif',
);
echo '<a href="http://www.suffolksportsforum.co.uk"><img src="', $banners[rand(0, count($banners) - 1)], '" alt="" /></a>';
If you want a different link for each banner then use this code:
$banners = array(
array('http://www.suffolksportsforum.co.uk/forumimages/fss.jpg', 'http://www.suffolksportsforum.co.uk'),
array('http://www.suffolksportsforum.co.uk/forumimages/coastal.jpg', 'http://www.suffolksportsforum.co.uk'),
array('http://www.suffolksportsforum.co.uk/forumimages/premier.gif', 'http://www.suffolksportsforum.co.uk'),
);
$rand = rand(0, count($banners) - 1);
echo '<a href="', $banners[$rand][1], '"><img src="', $banners[$rand][0], '" alt="" /></a>';
You can change the 'http://www.suffolksportsforum.co.uk' url to alter the location that they link to. :)
-
Thanks for this code LHVWB, really useful in so many ways.
Simple to amend for special offers, random forum links from a subset of posts chosen by admin as well as ads.
8)
-
Yeah it's quality.
Thanks very much for the help. One more quick question though:-
Can I add any text to this block and (oh thats two questions) can these links open in another page?
-
If you want a different link for each banner AND open in a new window then use this code:
$banners = array(
array('http://www.suffolksportsforum.co.uk/forumimages/fss.jpg', 'http://www.suffolksportsforum.co.uk'),
array('http://www.suffolksportsforum.co.uk/forumimages/coastal.jpg', 'http://www.suffolksportsforum.co.uk'),
array('http://www.suffolksportsforum.co.uk/forumimages/premier.gif', 'http://www.suffolksportsforum.co.uk'),
);
$rand = rand(0, count($banners) - 1);
echo '<a href="', $banners[$rand][1], '" target="_blank"><img src="', $banners[$rand][0], '" alt="" /></a>';
-
THANKS for a great block! ;D
-
Updated SP 2.2.2
now "Random Banner" shows nothing
:dead:
-
This works in the preview, but when I try to add the block it tells me there is a syntax error.
Any ideas what is causing it?
Thanks :)
-
Nobody knows the answer?
Hmm, I don't understand why it works in preview but won't let me add the block :/
-
Possibly an issue with the PHP syntax checking, try turning on the 'Disable PHP Validation' general setting.
Also, could you please post the exact code you are using? If there is an issue with the PHP syntax validation, then it would be quite useful.
-
Thanks, that did the trick.
Sorry, I didn't post the code because it was the same as the one above.
Thankyou :)
-
geekfairy,
Could you please post or send me (via PM) the exact code that you use in your PHP block? The code above returns no issues for me with SP 2.3 and SMF 1.1.10 or SMF 2RC1.2.
-
This code works great for a rotating banner but I have a couple questions - I'd like the image centered and any code I add results in a syntax error.
Also, I'd like to add some static text to the same block but that too results into a syntax error.
-
Is it possibile to have for each image a different caption text?
For example under the first image I'd like to have "First Image" (after a <br />), then under the second "Secondo Image", and so on... :)
-
Is it possibile to have for each image a different caption text?
For example under the first image I'd like to have "First Image" (after a <br />), then under the second "Secondo Image", and so on... :)
-
I thought I might share a nifty banner rotator script I use. You just drop all your images in a folder, and put a single php file in there with the images. Then you call the php file as if it were an image and it rotates everything in that folder randomly.
I've attached the file below.
If this doesn't make sense, you just create a folder, lets call it banners.
You just put all your image files in /banners
Put the BannerRotator.php file in /banners and then call /banners/BannerRotator.php where you would call the image (i.e. <img src="/BannerRotator.php" ) works with BBC too.
-
Hey stigmartyr
Any chance of having a peep at ya forum so we can see what it should look like?
-
Hey stigmartyr
Any chance of having a peep at ya forum so we can see what it should look like?
Sorry about taking a week to get back to you!
Here it is: http://stangnation.com/
It's the header banner that rotates on refresh.
I've removed as much flash as I possible could in favor of jQuery