Created
July 12, 2012 04:23
-
-
Save ekka21/3095710 to your computer and use it in GitHub Desktop.
Wordpress: load image automatically
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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