Multiple cover images of a subpage

Hello.

I would like to build a “cover image slider”. So I need to pick not just one but multiple images as cover. Is there any concept to achieve that with php or a cool kirby functions?

I tried this to implement some ideas from this: Filter to exclude files that contain specific string in their name

And i came up with this not working code:

<div class="cover_show">
<?php foreach ($cat as $item): ?>
<a class="image_container" href="<?= $item->url() ?>">
          <?=
        $files = $item->files()->filterBy('filename', '*=', 'cover')
          ?>
          <?php foreach ($files as $cover): ?>
            <?= $cover->cover()?>
          <?php endforeach; ?>
        </a>
<?php endforeach; ?>
</div>

cover function like this :

public function cover()
{
    return $this->content()->get('cover')->toFile() ?? $this->image();
}

It looks like the whole foreach part is doing nothing – the output is only the string of the images with cover in its filename.

Does anyone have an idea?

If $files returns an image collections, then $cover is already a file object, so no need to call cover():

<?php foreach ($files as $cover): ?>
  <?= $cover ?>
<?php endforeach; ?>

Thanks, it is working.