# Collection of images

**URL:** <https://forum.getkirby.com/t/collection-of-images/3354>\
**Category:** Questions\
**Tags:** v2\
**Created:** [February 17, 2016, 2:06am UTC](https://forum.getkirby.com/t/collection-of-images/3354 "2016-02-17T02:06:48Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![graphicmes](https://avatars.discourse-cdn.com/v4/letter/g/ee7513/32.png) [@graphicmes](https://forum.getkirby.com/u/graphicmes)\
**Post date:** [February 17, 2016, 2:06am UTC](https://forum.getkirby.com/t/collection-of-images/3354/1 "2016-02-17T02:06:48Z")

</div>

Hey Everyone, I’m racking my brain trying to figure out how I can display a collection of images across all folders on one page.

I want to run a search through all folders and display only the images where a match occurs.  
EX.  
Folder 1 - Image A  
Folder 2 - Image B  
Folder 3 - Image A

I want a page to display only folders with image A. Thanks in advance for all your help. Still learning and love to see what you all can do.

---

<div class="post-metadata">

**Author:** ![SQBiz](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/sqbiz/32/5014_2.png) [@SQBiz](https://forum.getkirby.com/u/SQBiz)\
**Post date:** [February 17, 2016, 4:47am UTC](https://forum.getkirby.com/t/collection-of-images/3354/2 "2016-02-17T04:47:04Z")

</div>

You might find `$pages->index()` handy:

```auto
$all_pages = $pages->index();

foreach ($all_pages as $page) {
  if ($page->images('image_a.jpg')) {
   $src = $page->images('image_a.jpg')->url();
   echo '<img src="' . $src '" />';
 }
}

```

untested but probably

---

<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:** [February 17, 2016, 7:13am UTC](https://forum.getkirby.com/t/collection-of-images/3354/3 "2016-02-17T07:13:11Z")

</div>

Should be `$page->image('some-image')` instead of `$page->images('some-image')`:

```php
<?php
$all_pages = $pages->index();
foreach ($all_pages as $page): ?>
 <?php if ($image = $page->image('image_a.jpg')): ?>
   <img src="<?php echo $image->url() ?>" >
 <?php endif ?>
<?php endforeach ?>

```

(And avoid echoing html tags …)

---

<div class="post-metadata">

**Author:** ![graphicmes](https://avatars.discourse-cdn.com/v4/letter/g/ee7513/32.png) [@graphicmes](https://forum.getkirby.com/u/graphicmes)\
**Post date:** [February 18, 2016, 8:10pm UTC](https://forum.getkirby.com/t/collection-of-images/3354/4 "2016-02-18T20:10:14Z")

</div>

@texnixe So I tried using what you gave me, but the page stops after the page uid. Thoughts?

```
<?php snippet('header') ?>
<div class="container">
    <div class="twelve columns section">
        <?php echo ($page->uid()) ?>
    </div>
    
        <?php
            $all_pages = $pages->index();
            foreach ($all_pages as $pa): ?>
                <?php if ($image = $pa->image()->filterBy('filename', '*=', 'HP')): ?>
                    <img src="<?php echo $image->url() ?>" >
                <?php endif ?>
        <?php endforeach ?>
</div>
<?php snippet('footer') ?>
```

---

<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:** [February 18, 2016, 8:14pm UTC](https://forum.getkirby.com/t/collection-of-images/3354/5 "2016-02-18T20:14:23Z")

</div>

You are using the `filterBy()` method on a single image:

```auto
<?php if ($image = $pa->image()->filterBy('filename', '*=', 'HP')): ?>

```

This will not work, because you can only filter a collection, so change this to

```auto
<?php if ($image = $pa->images()->filterBy('filename', '*=', 'HP')): ?>

```

And turn on debugging in your config.php to debug php errors:

```auto
c::set('debug', true);

```

---

<div class="post-metadata">

**Author:** ![graphicmes](https://avatars.discourse-cdn.com/v4/letter/g/ee7513/32.png) [@graphicmes](https://forum.getkirby.com/u/graphicmes)\
**Post date:** [February 24, 2016, 1:05am UTC](https://forum.getkirby.com/t/collection-of-images/3354/6 "2016-02-24T01:05:54Z")

</div>

Thank you. I’m learning so much. So this fixed my crashing problem, yet nothing comes up. It’s weird because using the same filter command on another page pulls in the correct image.

---

<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:** [February 24, 2016, 7:56am UTC](https://forum.getkirby.com/t/collection-of-images/3354/7 "2016-02-24T07:56:10Z")

</div>

There’s another problem in your code: Using a filter returns a $files collection, so you would need to use another foreach loop within the first one to output all members of the collection.

```php
<?php
$all_pages = $pages->index();
foreach ($all_pages as $pa): ?>
 <?php if ($images = $pa->image()->filterBy('filename', '*=', 'HP')): ?>
    <?php foreach ($images as $image): ?>
      <img src="<?php echo $image->url() ?>" >
    <?php endforeach ?>
 <?php endif ?>
<?php endforeach ?>

```

---

<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:00pm UTC](https://forum.getkirby.com/t/collection-of-images/3354/8 "2025-02-06T17:00:07Z")

</div>


