Skip to content

Instantly share code, notes, and snippets.

@ekka21
Created July 12, 2012 04:23
Show Gist options
  • Save ekka21/3095710 to your computer and use it in GitHub Desktop.
Save ekka21/3095710 to your computer and use it in GitHub Desktop.
Wordpress: load image automatically
<?php
//set images directory
$directory = 'wp-content/themes/mizzou/images/banners/';
try {
// create slideshow div to be manipulated by the above jquery function
echo "<div id=\"slideshow\">";
//iterate through the directory, get images, set the path and echo them in img tags.
foreach ( new DirectoryIterator($directory) as $item ) {
if ($item->isFile()) {
$path = $directory . "/" . $item;
echo "<img src=\"" . $path . "\" />";
}
}
echo "</div>";
}
//if directory is empty throw an exception.
catch(Exception $exc) {
echo 'the directory you chose seems to be empty';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment