View Full Version : do not show thumbnail if not in range

08-20-2012, 06:04 PM

my code below shows up to 6 thumbnail images I want to only show the thumbnails if there are more than 1 *note this one is not in the range: <img src="'.escape($directory['items']['photo']).'" alt="" />

Please help

if (!empty($directory['items']['photo'])) {
$list = array();
foreach ( range( 1, 6 ) as $i ) {
if ( ! $image = escape($directory["items"]["photo_$i"]))
$list[] = "<li><img src='$image' alt='' /></li>";
echo ' <div id="image" class="photo"></div>';
echo '<ul class="gallery">';
echo '<li class="active"><img src="'.escape($directory['items']['photo']).'" alt="" /></li>';

if ( $list )
echo implode( "\n", $list );
echo '</ul>';

08-20-2012, 07:17 PM
You just need a conditional statement based on the number of images involved, and the statement chooses between two blocks of code, one for a single image, the other for multiple images.

if (count($list)==1){ do this }
else{ do this stuff }

You may need something for no images too.

08-21-2012, 12:08 PM
thanks but that didn't work

08-21-2012, 04:45 PM
thanks but that didn't work

I changed the code, it should work now.