Hello.
I am stuck on something and have seen similar posts on here, but the solutions mentioned have not worked for me. So I thought I’d post my own.
What I want to achieve:
I have multiple posts that each contain many images which get displayed. I want to select one of those images to be displayed as the thumbnail/cover image on the parent page.
I have tried to add a checkbox to the image blueprint, so when the box is checked, that image is the one which is displayed as the thumbnail/cover image - but this is not working. I see the checkbox within the panel, but nothing gets rendered on the frontend.
What I added to the blueprint file:
cover_image:
label: Cover Image
type: checkboxes
options:
yes: Yes
text: Select this image as the cover image for the parent page
The code I added to the template file:
<ul class="grid-container gallery-list">
<?php foreach ($page->children()->flip() as $gallery): ?>
<li class="gallery">
<div class="gallery-details">
<?php $coverImage = $gallery->cover_image()->toFile();
if ($coverImage): ?>
<a href="<?= $gallery->url() ?>">
<img src="<?= $coverImage->url() ?>" alt="<?= $coverImage->alt() ?>" title="<?= $coverImage->title() ?>" class="cover-image" loading="lazy" height="100%" width="100%">
</a>
<?php endif ?>
<a href="<?= $gallery->url() ?>">
<p class="gallery-title"><?= $gallery->title() ?></p>
</a>
</div>
</li>
<?php endforeach ?>
</ul>
For the record, I’m a designer by day and someone who tries to make things work by night. So I hope you can see past any glaring errors I’ve made.
Thanks.