Simple Image Slideshow with jQuery and PHP

I really liked Jon Raasch’s jquery-powered slideshow, but integrating it into a page requires a bunch of steps:

  1. Add the jQuery library
  2. Add the slideshow javascript function
  3. Add the CSS with opacity and z-layer set properly
  4. Upload the images for the slideshow someplace
  5. Enumerate the images’ URLs that you want to cycle through

Adding images is tedious (you have to upload AND update the image list), and there’s no clean support for multiple slideshows per page. I wanted a process that made integration into other pages trivial.

I decided that an IFRAME to host the slideshow would keep jQuery and the slideshow CSS partitioned away from the rest of the embedding page, and would let adding slideshows to new pages have an easy-to-follow recipe, no matter what was already going on in the existing page. The IFRAME needed the template HTML, and if I used PHP, I could generate the image list for the slideshow automatically from the images that live in the same directory as the PHP script.

So here are the new instructions, using this IFRAME approach:

  1. Make a directory that will contain the images you want in the slideshow. For this example it’s “slideshow-demo
  2. Copy this file into the “slideshow-demo”  directory and name it index.php
  3. Copy the images for the slideshow into the directory.
    Remember to resize all the images to the same dimensions.
  4. On the page you want to embed the slideshow, add
    <iframe src ="slideshow-demo/" width="300" height="200"
      scrolling="no" frameborder="0"></iframe>

    Replace the width and height to be the common dimension of your images

Here’s a working demo:

Related posts:

  1. Simple PHP image rotation script
    This blog has a rotating header — if you visit /header/ and bounce on reload, you’ll see a series of random images. Here’s how it works: The header is added......
  2. Sandbox telegrams, or, how your Chrome extension can interact with page content scripts
    In AdGrok’s GrokBar, we inject a “heads-up display” on pages that the user is advertising. The heads-up display is actually an iframe that’s positioned within a browser-extension-injected div, and that......
  3. Simple 301 or 302 redirects with Apache or PHP
    It behooves you to make sure you’ve only got one URL that serves a given piece of content–so says google. But what if you’ve got a bunch of domains that......

  • http://foreverfrenchbulldogs.com/ Randy Baker

    Hello,
    I am looking for code for a slideshow. I like your idea for easily adding new slideshows to an existing page.
    Can you send me the code for your slideshow? I am not familiar with php – can you help me out?
    Thanks,
    Randy

  • http://matthew.mceachen.us matthew

    If your hosting provider only supports ASP, the index.php (that is here) could certainly be rewritten in ASP — just replace the 2 PHP code chunks that iterate through the current directory with ASP code.

  • Admin

    Hi Matt, you are a great person you just sved me alot of time and money, i was using  jquery with my smarty and didnt work on IE
    but now after i use the iframe and your code , i have fixed everything and you made my life easier today  :) thanks alot,