how to make rotating banner

Discussion in 'HTML & Website Design' started by Leriss, Jul 5, 2007.

  1. #1
    How can i make a rotating 468x60 banner at the header of my directory http://prwebdir.com ?

    It's now non-rotating but I would like to make it rotating, how to do that?

    Thanks,
    Adam.
     
    Leriss, Jul 5, 2007 IP
  2. Cloudberries

    Cloudberries Peon

    Messages:
    74
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Do you mean a banner which animates, and shows different frames over a period of time? Or a banner which changes on every page load, e.g. you might have 10 different banners you want to display, and have them show up randomly to visitors?

    (I'm assuming the latter, since you're offering an ad placement service there)
     
    Cloudberries, Jul 5, 2007 IP
  3. Leriss

    Leriss Well-Known Member

    Messages:
    506
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    130
    #3
    I mean the bold.
     
    Leriss, Jul 5, 2007 IP
  4. mattcch2007

    mattcch2007 Peon

    Messages:
    562
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    If you want one banner followed by next banner,use java applets.
    Using the .class file with parameters passed by its html tag.
     
    mattcch2007, Jul 5, 2007 IP
  5. Cloudberries

    Cloudberries Peon

    Messages:
    74
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Are you planning on coding something like this yourself?
    (if not, then I think there should be pre-existing banner rotation systems available)


    If you're using PHP then a simple (very simple) example might go something like this

    $banner1 = "banners/banner1.jpg";
    $banner2 = "banners/banner2.jpg";
    $banner3 = "banners/banner3.jpg";

    $banner_array = array($banner1, $banner2, $banner3);

    <img src="<?php echo $banner_array[rand(0,2)] ?>"/>

    --basically, all this is doing is storing the locations of the banners and then choosing one at random (the rand(0,2) function selects randomly between array location 0, 1 and 2)

    For a true banner rotation service though, you might want to store all the banners in a database, along with info about how many times they are to be shown per month. You should also make sure that they don't all get shown at once (like all 1000 displays within the first day, or something)

    All this would require a fair knowledge of PHP and MySQL (or whatever database is being used) though - or I guess you could do the same with text files. Let me know if I've just gone right over your head with this too :)
     
    Cloudberries, Jul 5, 2007 IP
  6. Leriss

    Leriss Well-Known Member

    Messages:
    506
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    130
    #6
    I just want to know how to mak 5 468x60 banners on my dir header to rotate randomly for the time they've been purchased for, like 1 month...will this work?
     
    Leriss, Jul 5, 2007 IP
  7. Cloudberries

    Cloudberries Peon

    Messages:
    74
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Yeah, I guess if that's all you're looking for, then what I suggested should work perfectly (just add higher numbers in rand() for more banners - well, I'm sure you can work all that out :) ).

    You'll probably do best just manually adding in the addresses pointing to each image, and then changing them at the end of the month
     
    Cloudberries, Jul 5, 2007 IP
  8. Leriss

    Leriss Well-Known Member

    Messages:
    506
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    130
    #8
    How to point website to a certain banner? i don't see any a href thingy :(
     
    Leriss, Jul 5, 2007 IP
  9. Cloudberries

    Cloudberries Peon

    Messages:
    74
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #9
    something like "banners/banner1.jpg" would be a "relative path"

    i.e. if your website is "http://www.website.com" and your banner is located at "http://www.website.com/banners/banner1.jpg", you would be able to use "banners/banner1.jpg" to reference it from the <img> tag

    It's probably best if you use something like...

    $banner1 = "http://www.website.com/banners/banner1.jpg";
    $banner2 = "http://www.website.com/banners/banner2.jpg";
    ... etc.

    though, keep things simple.
     
    Cloudberries, Jul 5, 2007 IP
  10. Cloudberries

    Cloudberries Peon

    Messages:
    74
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #10
    actually, think I misread your question :) sorry

    You could use another array, perhaps called

    $address_array = array("http://www.website1.com", "http://www.website2.com", "http://www.website3.com");

    and then use the code

    $chosen_banner = rand(0,2);
    <a href="<?php echo $address_array[$chosen_banner]; ?>"><img src="<?php echo $banner_array[$chosen_banner]; ?>"/></a>

    (just moving the random number into a variable, $chosen_banner, there)
     
    Cloudberries, Jul 5, 2007 IP
  11. Leriss

    Leriss Well-Known Member

    Messages:
    506
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    130
    #11
    I'm totaly confused now :p

    Could you please make me a ready to go code for example 2 banners?
    I think I'd be able to make the 5 later.
     
    Leriss, Jul 5, 2007 IP
  12. Cloudberries

    Cloudberries Peon

    Messages:
    74
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Yeah, I think I got a little carried away there :)

    Here's how it should look...

    
    <?php
    $banner1 = "http://www.yoursite.com/banners/banner1.jpg";
    $banner2 = "http://www.yoursite.com/banners/banner2.jpg";
    $banner3 = "http://www.yoursite.com/banners/banner3.jpg";
    
    $banner_array = array($banner1, $banner2, $banner3);
    $address_array = array("http://www.website1.com",  "http://www.website2.com", "http://www.website3.com");
    
    $chosen_banner = rand(0,2);
    ?>
    <a href="<?php echo $address_array[$chosen_banner]; ?>"><img src="<?php echo $banner_array[$chosen_banner]; ?>"/></a>
    
    Code (markup):
     
    Cloudberries, Jul 5, 2007 IP
  13. Leriss

    Leriss Well-Known Member

    Messages:
    506
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    130
    #13
    Leriss, Jul 5, 2007 IP
  14. Cloudberries

    Cloudberries Peon

    Messages:
    74
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #14
    The code itself should work, I tested it on my local server.

    I think something's not right with the PHP processing on your server though - I can see the PHP code (including the <?php and ?> tags) within the source code for the page (have a look at "view source" yourself, you'll see the php code still present in the text of the page)

    The index file's got a .php extension, so it should be working. It's something you'd need to check with your hosting provider I guess
     
    Cloudberries, Jul 5, 2007 IP
  15. Leriss

    Leriss Well-Known Member

    Messages:
    506
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    130
    #15
    I got the ad placed in a .tpl file becuase it was there by defualt...
    So it seems like .tpl doesn't support .php?
    Is there any other way then?
     
    Leriss, Jul 5, 2007 IP
  16. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #16
    You know, I've never understood why people open and close php so bloody much. It's just a waste of code, and makes flow logic a stone cold *****

    Simplify, simplify, simplify - and don't restate values you shouldn't have to.

    
    <?php
    $banner_list = array(
    	array('banner1.jpg','www.website1.com'),
    	array('banner2.jpg','www.website2.com'),
    	array('banner3.jpg','www.website3.com')
    );
    
    $chosen_banner=rand(0,count($banner_list));
    echo '
    	<a href="http://',$banner_list[$chosen_banner][1],'">
    		<img src="http://www.yoursite.com/banners/',$banner_list[$chosen_banner][0],'"/>
    	</a>
    ';
    ?>
    Code (markup):
    -- edit -- changed it to automatically count the number of links.
     
    deathshadow, Jul 5, 2007 IP
  17. Leriss

    Leriss Well-Known Member

    Messages:
    506
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    130
    #17
    http://prwebdir.com

    It's blank and on the blank there's '; ?>
     
    Leriss, Jul 5, 2007 IP
  18. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #18
    As a rule no... you cannot mix SSI/CGI's.

    Out of curiousity, what are you using server side to parse your .tpl? DocFlex? XSLT? Ruby?

    If ruby - all we need to do is rewrite this method in that... Either that or you throw that bloated slow pile of crap out the window and recode the whole site in php.

    Probably should have asked that up front - I assumed because everyone else wrote php examples you were using PHP - if you are using Ruby, then no you can't put php inside ruby any more than you could put ruby inside php. SSI/CGI's do not blend - once you start using one you CANNOT use another.

    Unfortunately I don't know Ruby apart from some of it's base syntax, which was enough for me to toss it in the trash for being a huge step BACKWARDS technologically... There's a reason we don't use fortran or smalltalk anymore.
     
    deathshadow, Jul 5, 2007 IP
  19. Cloudberries

    Cloudberries Peon

    Messages:
    74
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #19
    it was just a quick example :)

    I do aim to reduce open/closing as much as possible, but for large chunks of code, the endless streams of apostrophes and quotes and checking they all match up gives me a headache
     
    Cloudberries, Jul 5, 2007 IP
  20. Leriss

    Leriss Well-Known Member

    Messages:
    506
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    130
    #20
    Well, THAt .tpl file is for the header banner ONLY.
    It contained a html code by default with the banner.
    So far I've been using this code:

    <a href="http://prwebdir.com/contact.php"><img src="http://prwebdir.com/images/468x60.gif" border="1" alt="Header Ad"/></a>
     
    Leriss, Jul 5, 2007 IP