# Can't figure out how to display cover image

**URL:** <https://forum.getkirby.com/t/cant-figure-out-how-to-display-cover-image/13524>\
**Category:** Questions\
**Tags:** v3\
**Created:** [March 24, 2019, 4:22pm UTC](https://forum.getkirby.com/t/cant-figure-out-how-to-display-cover-image/13524 "2019-03-24T16:22:00Z")\
**Posts on this page:** 3\
**Page:** 2

<div class="post-metadata">

**Author:** ![pixelliquid](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/pixelliquid/32/10293_2.png) [@pixelliquid](https://forum.getkirby.com/u/pixelliquid)\
**Post date:** [March 27, 2023, 8:11pm UTC](https://forum.getkirby.com/t/cant-figure-out-how-to-display-cover-image/13524/22 "2023-03-27T20:11:30Z")

</div>

I see. Slowly getting there - much to read, much to learn. Especially when to use which method.

How can I iterate on the way to show the cover on the frontend view of the parent “productions” page? I can use the generic image check and get the first image, but I really like to check for & show the image with the “cover” template…

```auto
<?php foreach ($page->children()->listed() as $item): ?>
    <a href="<?= $item->url() ?>"><?= $item->title() ?>
        <?php if ($image = $item->images->findBy('template','cover')): ?>
            <img src="<?= $item->image()->url() ?>" alt="<?= $item->image()->alt() ?>">
        <?php endif ?>
    </a>
<?php endforeach ?>

```

Appreciate the help immensely!

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [March 27, 2023, 8:16pm UTC](https://forum.getkirby.com/t/cant-figure-out-how-to-display-cover-image/13524/23 "2023-03-27T20:16:43Z")

</div>

> [@pixelliquid](#):
>
> ```auto
> <?php if ($image = $item->images->findBy('template','cover')): ?>
> <img src="<?= $item->image()->url() ?>" alt="<?= $item->image()->alt() ?>">
> <?php endif ?>
> 
> ```

Almost, but you need to use the $image variable you defined, with your code, you fetch the intended image in the $image variable, but then display another image (`$item->image()`, which returns the first image in the folder). Also parentheses missing. Correct code:

```auto
<?php if ($image = $item->images()->findBy('template','cover')): ?>
   <img src="<?= $image->url() ?>" alt="<?= $image->alt() ?>">
<?php endif ?>

```

---

<div class="post-metadata">

**Author:** ![pixelliquid](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/pixelliquid/32/10293_2.png) [@pixelliquid](https://forum.getkirby.com/u/pixelliquid)\
**Post date:** [March 27, 2023, 8:19pm UTC](https://forum.getkirby.com/t/cant-figure-out-how-to-display-cover-image/13524/24 "2023-03-27T20:19:11Z")

</div>

Ha! Looks so simple 🙂  
… and after some time with Kirby it proves to _be_ simple as well

Thanks for making my day!

[Previous page](https://forum.getkirby.com/t/cant-figure-out-how-to-display-cover-image/13524.md?page=1)
