# How to fetch image from children pages

**URL:** <https://forum.getkirby.com/t/how-to-fetch-image-from-children-pages/10990>\
**Category:** Questions\
**Tags:** v2\
**Created:** [August 7, 2018, 12:28pm UTC](https://forum.getkirby.com/t/how-to-fetch-image-from-children-pages/10990 "2018-08-07T12:28:38Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ODD\_CODE](https://avatars.discourse-cdn.com/v4/letter/o/858c86/32.png) [@ODD\_CODE](https://forum.getkirby.com/u/ODD_CODE)\
**Post date:** [August 7, 2018, 12:28pm UTC](https://forum.getkirby.com/t/how-to-fetch-image-from-children-pages/10990/1 "2018-08-07T12:28:38Z")

</div>

I need help, please I am trying to fetch for an image from the children page. It shows a broken image icon on the page when I view it. Can someone share with me what I am doing wrong?

```
<?php foreach($page->children()->visible() as $subpage):?>
 <?php if($image = $subpage->coverImage()->first()): ?>
    <img src="<?php echo $image->url(); ?>" />
  <?php endif ?>
<?php endforeach ?>

```

---

<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:** [August 7, 2018, 12:40pm UTC](https://forum.getkirby.com/t/how-to-fetch-image-from-children-pages/10990/2 "2018-08-07T12:40:00Z")

</div>

> [@ODD\_CODE](#):
>
> \<?php if($image = $subpage-\>coverImage()-\>first()): ?\> \<img src=“\<?php echo $image-\>url(); ?\>” /\> \<?php endif ?\>

Is `coverImage` a field? What does it contain?

You can fetch the first of all images like this:

```auto
$image = $subpage->images()->first();

```

But not `coverage()->first()`

---

<div class="post-metadata">

**Author:** ![ODD\_CODE](https://avatars.discourse-cdn.com/v4/letter/o/858c86/32.png) [@ODD\_CODE](https://forum.getkirby.com/u/ODD_CODE)\
**Post date:** [August 7, 2018, 12:45pm UTC](https://forum.getkirby.com/t/how-to-fetch-image-from-children-pages/10990/3 "2018-08-07T12:45:30Z")

</div>

Removed the coverImage field and fetched the image first; works.  
But now the images are not showing up on the main page only subpage.

---

<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:** [August 7, 2018, 12:47pm UTC](https://forum.getkirby.com/t/how-to-fetch-image-from-children-pages/10990/4 "2018-08-07T12:47:37Z")

</div>

I don’t quite understand. Please provide some more context. In which template did you put that code? What do you want to fetch?

---

<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:** [August 7, 2018, 2:36pm UTC](https://forum.getkirby.com/t/how-to-fetch-image-from-children-pages/10990/6 "2018-08-07T14:36:37Z")

</div>

Have you sorted this out now? You deleted your answer…

---

<div class="post-metadata">

**Author:** ![ODD\_CODE](https://avatars.discourse-cdn.com/v4/letter/o/858c86/32.png) [@ODD\_CODE](https://forum.getkirby.com/u/ODD_CODE)\
**Post date:** [August 7, 2018, 3:26pm UTC](https://forum.getkirby.com/t/how-to-fetch-image-from-children-pages/10990/7 "2018-08-07T15:26:08Z")

</div>

I was able to get the image to display on the page. I am having other issues which, require me to learn more about Kirby cms. I am sure this a dumb question, how can you write clean else statement in Kirby?

---

<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:** [August 7, 2018, 3:43pm UTC](https://forum.getkirby.com/t/how-to-fetch-image-from-children-pages/10990/8 "2018-08-07T15:43:55Z")

</div>

What do you mean with clean else statement?

```auto
<?php
$a = 'hello';
$b = 'hallo';
if($a === $b) {
  echo "a is the same as b";
} else {
  echo "a is different from b";
}

```

I know that it is sometimes very difficult to ask the right questions if you are not very familiar with a topic. But please try to be more specific and give examples or post some code or tell us what you are trying to achieve. Otherwise trying to give the right answer is more guesswork than anything else.

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [February 6, 2025, 5:26pm UTC](https://forum.getkirby.com/t/how-to-fetch-image-from-children-pages/10990/9 "2025-02-06T17:26:31Z")

</div>

Archived on February 6, 2025, 5:26pm UTC


