I am trying to pull all images from a specified directory and then display them. I used the below piece of code in a regular website and it works
<?php $dirname = "images/tile/tile2/";
$images = glob($dirname."*.jpg");
foreach($images as $image) {
echo '<li><img src="'.$image.'" /><br /></li>';
}?>
I have now moved this code and modified it to a wordpress site and I get an empty array.
<?php $dirname = get_template_directory_uri()."/images/tile/tile1/";
$images = glob($dirname. "*.jpg");
//$images = glob($dirname."*. {jpg}", GLOB_BRACE); - tried with GLOB_RACE
foreach($images as $image) {
echo '<li><img src="'.$image.'" /><br /></li>';
}?>
Second code
<?php define('ACCREDPATH', get_template_directory_uri() . '/images/tile/tile1/');
$images = glob(ACCREDPATH. "*.jpg");
//$images = glob(ACCREDPATH. "*. {jpg}", GLOB_BRACE); - tried with GLOB_RACE
foreach($images as $image) {
echo '<li><img src="'.$image.'" /><br /></li>';
}?>
- I have checked that the images are in the folder
- I have done a var_dump and I am getting the right path.
- var_dump on the glob($images) gives array(0){ }
- I have also looked for other threads with this issue and still nothing
Please any help would be useful.