Jump to content

Show only the first image


gregory
 Share

Recommended Posts

Hi guys.
I would like to show only the first image as a preview of a slideshow. The code below shows the first image but is repeated. Do you know a solution? Thank you

//Call image
foreach($story->galleria as $img) {
  echo "<img src='{$story->galleria->first()->url}' alt='{$story->galleria->first()->description}'>";
}

 

Link to comment
Share on other sites

$out = '';
if(count($story->galleria)) {
    $firstImage = $story->galleria->first();
    $out = "<img src='{$firstImage->url}' alt='{$firstImage->description}'>";
}
else {
    // no images; do something else
}

echo $out;

 

Edited by kongondo
typos
  • Like 4
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...