BXslider images from folder

BXslider images folder

BXslider is one of the most popular slider scrips. And it’s really great when you are not adding new images to slider frequently. But I had situation on one website where I needed adding images often and I wanted to make that easier. So I made small adjustment and kind of addon so it can pull images from folder and add them in slider dynamically. You just need to add new image in folder you had set in script, and it will showup.

In HTML markup, where you need to enter:

<ul class="bxslider">
  <li><img src="/images/pic1.jpg" /></li>
  <li><img src="/images/pic2.jpg" /></li>
  <li><img src="/images/pic3.jpg" /></li>
  <li><img src="/images/pic4.jpg" /></li>

just add this instead:

<ul class="bxslider">
$handle = opendir(dirname(realpath(__FILE__)).'/photos/');
        while($file = readdir($handle)){
            if($file !== '.' && $file !== '..'){
                echo '<li><img src="photos/'.$file.'" border="0" /></li>';

Of course /photos/ is folder where your images are. Then when slider is up, and you need to add new image, just upload in to that folder and it will be updated.

/photos/ directory need to be in directory where the page is, or just change that part of code with apropriate path.

Photo by Beatrice Murch


Leave a Reply

Your email address will not be published. Required fields are marked *