...

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



jarv
08-20-2012, 05:04 PM
hi,

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"]))
continue;
$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>';

DrDOS
08-20-2012, 06: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.

jarv
08-21-2012, 11:08 AM
thanks but that didn't work

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

I changed the code, it should work now.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum