Question

I have a carousel on my website. Each slide looks like this:

<div class="item active">
    <a class="fancybox" rel="gallery1" href="img/gallery/country/large/01.jpg">
        <img src="img/gallery/country/thumb/01.jpg" alt="Default Image 1" />
    </a>
</div>
<div class="item">
    <a class="fancybox" rel="gallery1" href="img/gallery/country/large/01.jpg">
        <img src="img/gallery/country/thumb/01.jpg" alt="Image 2" />
    </a>
</div>  
<div class="item">
    <a class="fancybox" rel="gallery1" href="img/gallery/country/large/01.jpg">
        <img src="img/gallery/country/thumb/01.jpg" alt="Image 3" />
    </a>
</div>  

I am wanting to use php to scan a 'large' and 'thumb' folder of the images and to build the slider into the above format. If there are no images, there will be no output so no slider will display.

I have 2 folders here which I do not know if this will seriously complicate things. Alternatively, I can have any folder structure but ideally I would like a thumb file and a large image file.

So, does anyone have any suggestions for me? :)

Was it helpful?

Solution 2

Perhaps something like:

// this assumes that ABC.JPG exists in both "img/gallery/country/thumb/" and "img/gallery/country/large/"!
$thumbs = glob("img/gallery/country/thumb/*.jpg");

if(count($thumbs)) {
  natcasesort($thumbs);
  foreach($thumbs as $thumb) {
    ?>
    <div class="item">
        <a class="fancybox" rel="gallery1" href="img/gallery/country/large/<?php echo basename($thumb) ?>">
            <img src="<?php echo $thumb ?>" alt="" />
        </a>
    </div>  
    <?php
  }
} else {
  echo "No images";
}

OTHER TIPS

Use glob to find your files:

<?php
foreach (glob("img/gallery/country/large/*.jpg") as $image) {
  echo $image;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top