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

Wordpress plug-in to rotate background images

  • Is there a wordpress plug-in to rotate background images? I can't decide between a few for this site and though it might be good to randomly rotate a 2 or 3 different ones. Is this possible?

    www.kamcheng.net
  • do you want it to choose from a set and randomly display on on page load?
    http://css-tricks.com/snippets/php/randomize-background-image/

    or do you want the image to change while the user is viewing the page? This is also doable but sounds pretty distracting if its a background image on the body.
  • Why does it say that the PHP goes ABOVE the DOCTYPE? Nothing should go above the DOCTYPE??? Right?
  • use this image rotator, i am not sure if if a plug-in though.

  •     <script type="text/javascript">
        // # of images
        var imgCount = 4;
        // image directory
        var dir = 'http://yourdomain.com/images/bg/';
        // random the images
        var randomCount = Math.round(Math.random() * (imgCount - 1)) + 1;
        // array of images & file name
        var images = new Array
        images[1] = "1.jpg",
        images[2] = "2.jpg",
        images[3] = "3.jpg",
        images[4] = "4.jpg";
        document.body.style.backgroundImage = "url(" + dir + images[randomCount] + ")";
        </script>
    

    A little javascript for randomise your body background ...

  • Why does it say that the PHP goes ABOVE the DOCTYPE? Nothing should go above the DOCTYPE??? Right?

    Pretty much all server side languages can go above the DOCTYPE. In the example you mention, PHP processes the variables so they are available within the document. Nothing actually gets outputted above the DOCTYPE.