treehouse : what would you like to learn today?
Web Design Web Development iOS Development

random images

  • is there a way of adding a script to randomly pick images from a folder. What i need is a new image everytime someone visits the homepage.

    At the moment its setup to output images using a custom field in wordpress but i can not find somthing to get it to pick random photo's on each visit.

    Any help would be great.

    Thanks

    B
  • as rob has said, that thread has a few ideas, mine is best though ;)
  • I use

    <?php
    function randomImage ( $array ) {
    $total = count($array);
    $call = rand(0,$total-1);
    return $array[$call];
    }
    $my_images = array (
    \"com.jpg\",
    \"image.jpg\",
    \"etc.jpg\"
    );
    $img = randomImage($my_images);
    ?>

    <?php echo '<img src=\"http://imgurl.com/'.$img.'\" />'; ?>