# How to output sibling children images on index

**URL:** <https://forum.getkirby.com/t/how-to-output-sibling-children-images-on-index/4134>\
**Category:** Questions\
**Tags:** v2\
**Created:** [May 17, 2016, 11:12am UTC](https://forum.getkirby.com/t/how-to-output-sibling-children-images-on-index/4134 "2016-05-17T11:12:35Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![davabo](https://avatars.discourse-cdn.com/v4/letter/d/4491bb/32.png) [@davabo](https://forum.getkirby.com/u/davabo)\
**Post date:** [May 17, 2016, 11:12am UTC](https://forum.getkirby.com/t/how-to-output-sibling-children-images-on-index/4134/1 "2016-05-17T11:12:35Z")

</div>

Hey guys,

**My site is currently built like this:**

```
Home.php
About.php
    About-1.php
    About-2.php
    About-3.php
Contact.php

```

Inside the 3 about children pages I currently have images inside my structure field in my blueprints. I am trying to pull these images to the main home page.

**About child pages blueprint:**

```
`featuredimage: 
    label: Slider Image
    type: structure
    width: 1/4
    entry: >
      <img src="{{image}}" />
    fields: 
      image:
        label: Image
        type: select
        options: query
        query:
          fetch: files
          value: '{{url}}'
          text: '{{filename}}'`

```

So logically, To output these images onto home.php I would first have to access my sibling about page, then access its children and then the image fields.

```
<?php $images = $pages->find('about'); ?>
			<?php $imagechilds = $images->children(); ?>
		  		<?php foreach($imagechilds as $m): ?>
		  			<?php foreach ($m->featuredimage() as $i): ?>
		  				<img src="<?php echo $i["image"];?>">
		  			<?php endforeach; ?>

```

I have been trying code like this so far but I’m having zero luck. If anyone could help it would be greatly appreciated. Thank you.

---

<div class="post-metadata">

**Author:** ![Thiousi](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/thiousi/32/13656_2.png) [@Thiousi](https://forum.getkirby.com/u/Thiousi)\
**Post date:** [May 17, 2016, 11:18am UTC](https://forum.getkirby.com/t/how-to-output-sibling-children-images-on-index/4134/2 "2016-05-17T11:18:48Z")

</div>

Hello @davabo  
I think something similar has already been discussed on the forum. One of the solutions would be

```auto
 $aboutPage = $page('about');
   $imagechilds = $aboutPage->children()->files()->filterBy('type', 'image');

```

And then loop through them.

Reference link:

> [@Trying to make a Gallery from all images from a folder children](https://forum.getkirby.com/t/trying-to-make-a-gallery-from-all-images-from-a-folder-children/4105/7):
>
> hey @texnixe ended up using this and it seemed to work. Thanks again for your help. $journalPage = $pages-\>find('journal'); $images = $journalPage-\>children()-\>files()-\>filterBy('type', 'image'); echo guggenheim($images, array('width' =\> 1200, 'height' =\> 350, 'border' =\> 8)); ?\>`

---

<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:** [May 17, 2016, 11:39am UTC](https://forum.getkirby.com/t/how-to-output-sibling-children-images-on-index/4134/3 "2016-05-17T11:39:23Z")

</div>

If I haven’t inserted any typos, this should work:

```auto
<?php
 $childPages = page('about')->children();
 foreach($childPages as $p): ?>
   <?php foreach ($p->featuredimage()->toStructure() as $item): ?>
	<img src="<?php echo $item->image();?>">
   <?php endforeach; ?>
<?php endforeach ?>

```

---

<div class="post-metadata">

**Author:** ![davabo](https://avatars.discourse-cdn.com/v4/letter/d/4491bb/32.png) [@davabo](https://forum.getkirby.com/u/davabo)\
**Post date:** [May 17, 2016, 12:00pm UTC](https://forum.getkirby.com/t/how-to-output-sibling-children-images-on-index/4134/4 "2016-05-17T12:00:37Z")

</div>

Thank you very much for both replies, they really helped!

The images are now being output onto the home page.

But I have one more question, How do i single out the specific images?

For example, since I have 3 child pages, each with 1 image on each page, when i ran that code above all 3 images appeared. When I only want the one from each specific child page.

Let me take a screenshot and show you what I mean.

[Screenshot](http://prntscr.com/b52rru)

I want a single image in each, not 3 inside 1. I tried using the offset value but that didn’t work.

So for example, The first child page image should be in row 1, the second row 2, the third row 3 etc…

---

<div class="post-metadata">

**Author:** ![Thiousi](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/thiousi/32/13656_2.png) [@Thiousi](https://forum.getkirby.com/u/Thiousi)\
**Post date:** [May 17, 2016, 12:12pm UTC](https://forum.getkirby.com/t/how-to-output-sibling-children-images-on-index/4134/5 "2016-05-17T12:12:55Z")

</div>

Could you share your template code?  
Judging by the screenshot you’re calling the function inside the first block only.  
You’d need to include the block code inside your each loop.

---

<div class="post-metadata">

**Author:** ![davabo](https://avatars.discourse-cdn.com/v4/letter/d/4491bb/32.png) [@davabo](https://forum.getkirby.com/u/davabo)\
**Post date:** [May 17, 2016, 1:09pm UTC](https://forum.getkirby.com/t/how-to-output-sibling-children-images-on-index/4134/6 "2016-05-17T13:09:18Z")

</div>

`

```
<section class="three full">
<div>
	<a href="#">
	  	
		<?php
			$childPages = page('about')->children()->offset(0);
				foreach($childPages as $p): ?>
					<?php foreach ($p->featuredimage()->toStructure() as $item): ?>
						<img src="<?php echo $item->image()?>">
					<?php endforeach; ?>
						<?php endforeach ?>

		<div class="info">
			<h4>The Food</h4>
			<span>Read More</span>
		</div>
	</a>	
</div>
<div>
	<a href="">
		<img src="http://placehold.it/360x500" alt="">
		<div class="info">
			<h4>The People</h4>
			<span>Read More</span>
		</div>
	</a>	
</div>
<div>
	<a href="#">
		<img src="http://placehold.it/360x500" alt="">
		<div class="info">
			<h4>The Place</h4>
			<span>Read More</span>
		</div>
	</a>	
</div>

```

`

So my goal was to get the correct image showing in the first div, then id fiddle with the code to produce the 2nd and third in the other divs. I just have placeholder images setup for the time being. They will be replaced with the code.

---

<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:** [May 17, 2016, 1:16pm UTC](https://forum.getkirby.com/t/how-to-output-sibling-children-images-on-index/4134/7 "2016-05-17T13:16:05Z")

</div>

```auto
<?php
 $childPages = page('about')->children();
 foreach($childPages as $p): ?>
  <div>
      <?php foreach ($p->featuredimage()->toStructure() as $item): ?>
        <a href="">
	   <img src="<?php echo $item->image()?>">
           <div class="info">
	     <h4>The People</h4>
	     <span>Read More</span>
	   </div>
       </a>	
     <?php endforeach; ?>
  </div>    
<?php endforeach ?>

```

What I don’t understand is why you are using a structure field here for only this one item?

---

<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, 4:55pm UTC](https://forum.getkirby.com/t/how-to-output-sibling-children-images-on-index/4134/8 "2025-02-06T16:55:28Z")

</div>

Archived on February 6, 2025, 4:55pm UTC


