Is this possible with PHP inside WordPress.
Basically if I have a directory in my site called "promos" that consists of 1 to many images (as these images can change), that I would like to read from within a PHP file into a carousel setup, i.e. something similar to this:
<div class="scrollable" id="browsable">
<div class="items">
<?php
$tot_images_from_promo_dir = [get_total_image_count_in_promos_dir];
for ( $counter = 1; $counter <= $tot_images_from_promo_dir; $counter ++) {
echo "<div>";
echo "<a href="#"><img src="[image_from_promo_directory]" /></a>
echo "</div>";
}
?>
</div>
</div>
Hope the above makes sense, but basically want to somehow with php read total amount of images in my promo directory and then use this total in my loop max value and read each image file name in the promo directory and pass into my
Would really appreciate the php syntax to do this.
Thanks.
I use glob for such operations
Assuming that all files in the promos directory are images:
If, however, there are files in the directory that are not images, you would need to check that before showing it. The while loop would need to change to something like:
How about the DirectoryIterator class?
Go thou unto http://www.php.net/manual/en/ref.dir.php and look in particular at the scandir function. You can use something like:
You get to write the is_an_image() function.
This code will provides the images from the directory called "imagfolder"
My way to do it with
opendir