1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

I need simple PHP code that displays one of three images randomly

Discussion in 'PHP' started by le007, May 30, 2015.

  1. #1
    Hi all,

    I added a new wordpress plugin called "AdRotate". I don't want to just rotate a group of ads, I want specific ones to randomly appear or even appear in a sequence.

    Can you please tell me how to randomly have either of these appear on my site?:

    <?php echo adrotate_ad(1); ?> or <?php echo adrotate_ad(2); ?>

    Thanks,
    Le007
     
    le007, May 30, 2015 IP
  2. ri2014

    ri2014 Greenhorn

    Messages:
    6
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    23
    #2
    just add randomize function like <?php echo adrotate_ad(rand(1,2)); ?>
    more here http://php.net/manual/en/function.rand.php

    or I can code custom script for u if you wish?
     
    Last edited: May 30, 2015
    ri2014, May 30, 2015 IP
    Karen May Jones likes this.
  3. le007

    le007 Well-Known Member

    Messages:
    481
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #3
    Thanks for the reply. Can I do <?php echo adrotate_ad(rand(1,2,3,4,5)); ?> too?
    I guess for a custom script, I'd like them to appear on an equal basis. 10 times for one, 10 for another etc
     
    le007, May 31, 2015 IP
  4. ri2014

    ri2014 Greenhorn

    Messages:
    6
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    23
    #4
    nop please read function manual
     
    ri2014, May 31, 2015 IP
  5. le007

    le007 Well-Known Member

    Messages:
    481
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #5
    So I can't randomize more than 2 images? Because I have 4 images I need to randomize
     
    le007, May 31, 2015 IP
  6. ri2014

    ri2014 Greenhorn

    Messages:
    6
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    23
    #6
    then use <?php echo adrotate_ad(rand(1,4)); ?>
     
    ri2014, May 31, 2015 IP
  7. le007

    le007 Well-Known Member

    Messages:
    481
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #7
    Ok, thank you for your help.
     
    le007, May 31, 2015 IP
  8. papa_face

    papa_face Notable Member

    Messages:
    2,237
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    285
    #8
    papa_face, May 31, 2015 IP
  9. le007

    le007 Well-Known Member

    Messages:
    481
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #9
    Thank you papa_face, that actually will work well too! Thank you :)
     
    le007, Jun 9, 2015 IP