# Check if structure field contains more than one item

**URL:** <https://forum.getkirby.com/t/check-if-structure-field-contains-more-than-one-item/10449>\
**Category:** Questions\
**Tags:** v2\
**Created:** [May 19, 2018, 9:14am UTC](https://forum.getkirby.com/t/check-if-structure-field-contains-more-than-one-item/10449 "2018-05-19T09:14:06Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jimbobrjames](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jimbobrjames/32/5802_2.png) [@jimbobrjames](https://forum.getkirby.com/u/jimbobrjames)\
**Post date:** [May 19, 2018, 9:14am UTC](https://forum.getkirby.com/t/check-if-structure-field-contains-more-than-one-item/10449/1 "2018-05-19T09:14:06Z")

</div>

Seems like a daft question but I cant seem to find the answer to this anywhere. Im using the [images plugin](https://github.com/medienbaecker/kirby-images) which feeds a javascript slide show. if there is only one entry in the images field (which is technically a structure field), I want to just display that image on its own without the markup for the slideshow since there is no point.

How do i check if a structure has only one entry or more than one entry?

---

<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 19, 2018, 9:29am UTC](https://forum.getkirby.com/t/check-if-structure-field-contains-more-than-one-item/10449/2 "2018-05-19T09:29:43Z")

</div>

The `yaml()` method gives you an array. So you can use standard php methods to deal with an array:

```auto
<?= count($page->gallery()->yaml()) ?>

```

echos the number of elements in an array.

---

<div class="post-metadata">

**Author:** ![jimbobrjames](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jimbobrjames/32/5802_2.png) [@jimbobrjames](https://forum.getkirby.com/u/jimbobrjames)\
**Post date:** [May 19, 2018, 9:32am UTC](https://forum.getkirby.com/t/check-if-structure-field-contains-more-than-one-item/10449/3 "2018-05-19T09:32:05Z")

</div>

Thanks… I Probably should have mentioned i’m using `toStucture()`

surely theres a shorter way… this works but looks hideous

```auto
  <?php
  if($page->productimages()->toStructure()->count() > 1 )
  {
    $imageclass = "shop-product-media-set";
  } else {
    $imageclass = "shop-product-media-single";
  }
  ?>

```

---

<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 19, 2018, 9:44am UTC](https://forum.getkirby.com/t/check-if-structure-field-contains-more-than-one-item/10449/4 "2018-05-19T09:44:33Z")

</div>

Yes, you should have mentioned that…😉

If you just want a classname, you can use the ternary. operator

```auto
$imageclass = $page->productimages()->toStructure()->count() > 1? 'shop-product-media-set':'shop-product-media-single';

```

If you need different html output, you better stick with if-else.

---

<div class="post-metadata">

**Author:** ![jimbobrjames](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jimbobrjames/32/5802_2.png) [@jimbobrjames](https://forum.getkirby.com/u/jimbobrjames)\
**Post date:** [May 19, 2018, 9:48am UTC](https://forum.getkirby.com/t/check-if-structure-field-contains-more-than-one-item/10449/5 "2018-05-19T09:48:37Z")

</div>

Thats better 🙂

Don’t need new markup, my base html works a treat with [Tiny Slider](http://ganlanyuan.github.io/tiny-slider/). I just need to flip a class.

I cleaned it up a little further…

```auto
<?php
$imageset = $page->productimages()->toStructure();
$imageclass = $imageset->count() > 1? 'shop-product-media-set':'shop-product-media-single';
?>
<div id="product-slides" class="<?= $imageclass ?>">
  <?php foreach($imageset as $image): ?>
    <?php if($image = $page->image($image)): ?>
    <figure class="product-thumb">
      <?= $image->focusCrop(800,600)->html(); ?>
    </figure>
    <?php endif ?>
  <?php endforeach; ?>
</div>

```

---

<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:28pm UTC](https://forum.getkirby.com/t/check-if-structure-field-contains-more-than-one-item/10449/6 "2025-02-06T17:28:15Z")

</div>


