The problem is that it only works with the name of the image.
I would like to display the image with an id or by “sort” (position 1 or 2) because if I change the name of the image it requires updating the code of the page on the front.
Note that you better leave the image’s alt attribute empty if it doesn’t provide useful information about the image. Ideally, if the image is important, the alt attribute should describe the image.
<?php
if (($p = page('home-1-la-cave')) && $p->hasImages()) :
$images = $p->images()->sortBy('sort', 'asc');
foreach ($images as $image) :
echo $image; # <!-- This should print the image tag by default if I remember correctly
endforeach;
endif;
?>
<?php
if (($p = page('home-1-la-cave')) && $p->hasImages('title')) :
$images = $p->images()->sortBy('sort', 'asc');
foreach ($images as $image) :
//echo $image; # <!-- This should print the image tag by default if I remember correctly
echo '<img src="'.$image->url().'" title="'.$image->title().'" alt="'.$image->alt().'" />' ;
endforeach;
endif;
?>
I have another problem. I have 5 images in total and I have selected only 3. The problem is that there are 5 images displayed. While I want to display only 3.