Listing image files from a directory for SlidesJS to make into a slider on a Wordpress website.


Staff member
So, I've got the Slides JS correctly set-up but I want to create a PHP code to list files from a directory, if possible by modified date first.

This is the code that I've got so far:

<div id="slides">
<div class="slides_container">
$directory = "/wp-content/themes/1/img/";

$images = glob("" . $directory . "*.jpg");

$imgs = '';

foreach($images as $image){ $imgs[] = "$image"; }

foreach ($imgs as $img) {

    echo "<div>
            <img src='$img' />
          </div> ";

Which from my understanding should list the .jpg images in the directory as:

  <img src="image_src_here.jpg" />

But it's not listing anything - do i need to add this as a function to wordpress?

Secondly, how can I list the images by modified date, is this possible?