<?php $imageArr = glob( rtrim( $_SERVER['DOCUMENT_ROOT'] , '/' ).'/images/carousel-*.jpg' ); shuffle( $imageArr ); $outPattern = '<div class="image-entry"><img src="%s" /></div>'; foreach( $imageArr as $carImage ) echo sprintf( $outPattern , $carImage )."\n";
The advantages of this solution are that it will automatically detect all images with the name carousel-X.jpg in the image folder and use them in the carousel.
Or even:
<?php $imageArr = glob( rtrim( $_SERVER['DOCUMENT_ROOT'] , '/' ).'/images/carousel-*.jpg' ); shuffle( $imageArr ); if( count( $imageArr ) ){ echo '<div class="image-entry"><img src="'.implode( '" /></div><div class="image-entry"><img src="' , $imageArr ).'" /></div>'; }else{ echo '<!-- No Images in Array //-->'; }
Luke stevenson
source share