# Homepage with random selected images / Kirby 2

**URL:** <https://forum.getkirby.com/t/homepage-with-random-selected-images-kirby-2/21017>\
**Category:** Questions\
**Tags:** v2\
**Created:** [February 1, 2021, 5:26pm UTC](https://forum.getkirby.com/t/homepage-with-random-selected-images-kirby-2/21017 "2021-02-01T17:26:51Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![StudioOlivierGassies](https://avatars.discourse-cdn.com/v4/letter/s/7993a0/32.png) [@StudioOlivierGassies](https://forum.getkirby.com/u/StudioOlivierGassies)\
**Post date:** [February 1, 2021, 5:26pm UTC](https://forum.getkirby.com/t/homepage-with-random-selected-images-kirby-2/21017/1 "2021-02-01T17:26:51Z")

</div>

Hello,

I try to have on the home page of the site, a random image among a selection of images coming from different portfolio pages of the site ([www.oliviergassies.fr](http://www.oliviergassies.fr), for the moment the site shows random images of the homepage).

For that I thought to create via blueprint for the portfolio template a toogle field for images. I toggle images I want for homepage. And then one toggled image is selected randomly and showed on hompage. But…

Here details

In the portfolio.yml blueprint :

```
files:
  sortable: true
  fields:
    featured:
      label: Featured
      type: toggle

```

On the home.php page :

`<?php $featured = $pages->children()->visible()->images()->shuffle('true')->first(); ?>`

Thank you for your help,  
Best

---

<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 1, 2021, 5:40pm UTC](https://forum.getkirby.com/t/homepage-with-random-selected-images-kirby-2/21017/2 "2021-02-01T17:40:28Z")

</div>

I’m a bit confused, what is `files`, how can files have a field?

Ah, sorry, Kirby 2…

You would have to get the images of all pages filtered by the toggle field

```auto
<?php $featured = $pages->children()->visible()->images()->filterBy('featured', true)->shuffle()->first(); ?>

```

---

<div class="post-metadata">

**Author:** ![StudioOlivierGassies](https://avatars.discourse-cdn.com/v4/letter/s/7993a0/32.png) [@StudioOlivierGassies](https://forum.getkirby.com/u/StudioOlivierGassies)\
**Post date:** [February 1, 2021, 5:46pm UTC](https://forum.getkirby.com/t/homepage-with-random-selected-images-kirby-2/21017/3 "2021-02-01T17:46:57Z")

</div>

Here is my entire blueprint

```
title: Portfolio

files:
  sortable: true
  fields:
    featured:
      label: Featured
      type: toggle

pages: false

fields:
  title:
    label: Title
    type: text
    width: 1/2
  private:
    label: Private
    type: checkbox
    text: Private page
    width: 1/2
  types:
    label: Type
    type: tags
    width: 1/2
  editors:
    label: Editors
    type: tags
    width: 1/2
  years:
    label: Years
    type: tags
    width: 1/2
  series:
    label: Series
    type: tags
    width: 1/2
  description:
    label: Text
    type: textarea 
  tag:
    label: Description for robots
    type: textarea
```

---

<div class="post-metadata">

**Author:** ![StudioOlivierGassies](https://avatars.discourse-cdn.com/v4/letter/s/7993a0/32.png) [@StudioOlivierGassies](https://forum.getkirby.com/u/StudioOlivierGassies)\
**Post date:** [February 1, 2021, 6:34pm UTC](https://forum.getkirby.com/t/homepage-with-random-selected-images-kirby-2/21017/4 "2021-02-01T18:34:09Z")

</div>

Thank you for the answer.  
I can not make it work.

---

<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 1, 2021, 6:35pm UTC](https://forum.getkirby.com/t/homepage-with-random-selected-images-kirby-2/21017/5 "2021-02-01T18:35:01Z")

</div>

What does the toggle field actually store in the files meta data?

And what exactly is the issue? No image at all, wrong image?

---

<div class="post-metadata">

**Author:** ![StudioOlivierGassies](https://avatars.discourse-cdn.com/v4/letter/s/7993a0/32.png) [@StudioOlivierGassies](https://forum.getkirby.com/u/StudioOlivierGassies)\
**Post date:** [February 1, 2021, 7:10pm UTC](https://forum.getkirby.com/t/homepage-with-random-selected-images-kirby-2/21017/6 "2021-02-01T19:10:10Z")

</div>

An exemple of the content in the file metadata :

```
Featured: true

```

All pictures are shown.

---

<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 1, 2021, 7:14pm UTC](https://forum.getkirby.com/t/homepage-with-random-selected-images-kirby-2/21017/7 "2021-02-01T19:14:21Z")

</div>

> [@StudioOlivierGassies](#):
>
> All pictures are shown.

But ` first()` returns only a single image, so it can’t really show all images. Or do you mean, a random single image out of all images, not only the featured ones.

Anyway, try with a string instead of a boolean:

```auto
<?php $featured = $pages->children()->visible()->images()->filterBy('featured', 'true')->shuffle()->first(); ?>

```

---

<div class="post-metadata">

**Author:** ![StudioOlivierGassies](https://avatars.discourse-cdn.com/v4/letter/s/7993a0/32.png) [@StudioOlivierGassies](https://forum.getkirby.com/u/StudioOlivierGassies)\
**Post date:** [February 1, 2021, 7:16pm UTC](https://forum.getkirby.com/t/homepage-with-random-selected-images-kirby-2/21017/8 "2021-02-01T19:16:21Z")

</div>

Sorry, i mean a random image out of all images.  
This works,  
Thank you !  
Best

---

<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:23pm UTC](https://forum.getkirby.com/t/homepage-with-random-selected-images-kirby-2/21017/9 "2025-02-06T17:23:01Z")

</div>

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


