Is there a way to Rotate Ads in sidebar?

Discussion in 'WordPress' started by MiletNZ, Sep 21, 2010.

  1. #1
    I have a small picture ad in my sidebar, I want to show off more than one ad with a different link on each one so can't just do an animated picture. What can I do?

    At the moment all I'm using to do it is
    
    <div id="sidebar-ads">
    <a href="AD LINK"><img src="<?php echo get_option('home'); ?>/wp-content/themes/mytheme/images/banners/Ad.png" alt="AD ALT TEXT" width="300px" height="250px" /></a>
    
    </div>
    Code (markup):
     
    MiletNZ, Sep 21, 2010 IP
  2. deluxdon

    deluxdon Catch Me If You Can...!!!™ Staff

    Messages:
    25,482
    Likes Received:
    1,943
    Best Answers:
    32
    Trophy Points:
    480
    #2
    There are plugin available for that. Just try to search it through google search.

    DON.
     
    deluxdon, Sep 21, 2010 IP
  3. MiletNZ

    MiletNZ Member

    Messages:
    283
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    30
    #3
    I have been doing that but will look again
     
    MiletNZ, Sep 21, 2010 IP
  4. asdirc

    asdirc Active Member

    Messages:
    275
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #4
    If you want i can help you ... to make such a script. How many ads do you want to rotate? you want random rotate no ?
     
    asdirc, Sep 21, 2010 IP
  5. MiletNZ

    MiletNZ Member

    Messages:
    283
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    30
    #5
    Thanks, but as we are a non-profit organization, we do not have the funds available to pay for such services.

    The Size of the ad is width="300px" height="250px"
    We want to rotate 4 ads at this time but want to be able to customize this
    Don't really mind about order number

    We don't have all 4 ads finished yet though

    Maybe someone could help write up a template (or what ever works - I'm no programmer) in exchange for a backlink on our site
     
    MiletNZ, Sep 21, 2010 IP
  6. reviewmylife

    reviewmylife Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    If you just want to rotate 4 (or however many) ad blocks you could just use a bit of JavaScript like this. It will randomly pick one of 4 ads, with an equal probability of picking each one.

    <script type="text/javascript">
    var random = Math.random();
    if (random < 0.25) {
    // put ad1 here
    }
    else if (random <0.5) {
    // put ad2 here
    }
    else if (random <0.75) {
    // put ad3 here
    }
    else {
    // put ad4 here
    }
    </script>
     
    reviewmylife, Sep 21, 2010 IP
  7. MiletNZ

    MiletNZ Member

    Messages:
    283
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    30
    #7
    Thanks for that! In the ad section, do I just insert the images full link? Can I also put in a different hyperlink for each ad? Thanks again!
     
    MiletNZ, Sep 21, 2010 IP
  8. reviewmylife

    reviewmylife Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    You'll need to use document.write to output your links.

    e.g.

    <script type="text/javascript">
    var random = Math.random();
    if (random < 0.25) {
    <!--
    document.write('<a href="http://youlink...">yourlink</a>');
    //-->
    }
     
    reviewmylife, Sep 21, 2010 IP
  9. jahangir

    jahangir Peon

    Messages:
    633
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #9
    jahangir, Sep 21, 2010 IP
  10. MiletNZ

    MiletNZ Member

    Messages:
    283
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    30
    #10
    Thanks so much for this will give it a go
     
    MiletNZ, Sep 22, 2010 IP
  11. zhoom

    zhoom Peon

    Messages:
    388
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #11
    zhoom, Sep 22, 2010 IP
  12. MiletNZ

    MiletNZ Member

    Messages:
    283
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    30
    #12
    I couldn't figure the document.write option so I went with this generator and it worked well thanks
     
    MiletNZ, Sep 22, 2010 IP
  13. jahangir

    jahangir Peon

    Messages:
    633
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #13
    ^ I am glad it solved your problem :)
     
    jahangir, Sep 22, 2010 IP