Assign additional class to the first image in a slideshow

Hello,

I’m building my very first project with Kirby and learning a lot by doing so :slightly_smiling_face:

However, I ran into the following problem:

For a slideshow, I need the first image to have an additional class (“visible”). This is my code:

<?php foreach ($gallery as $image): ?>
	<?php if($image->isFirst() === true): ?>
		<figure class="slide-projekt visible">
			<img src="<?= $image->url() ?>">
		</figure>
	<?php else: ?>
		<figure class="slide-projekt">
			<img src="<?= $image->url() ?>">
		</figure>
	<?php endif ?>
<?php endforeach ?>

I have a folder with 12 images, and the generated HTML code assigns the “visible” class to the sixth instead of the first.

What am I doing wrong?

Many thanks!

Pass $gallery as parameter to isFirst() so that the context is known, otherwise, all images in the folder will be used as reference.

1 Like

Cheers!