# Limit number of structure entries

**URL:** <https://forum.getkirby.com/t/limit-number-of-structure-entries/4784>\
**Category:** Questions\
**Tags:** v2\
**Created:** [July 25, 2016, 3:13pm UTC](https://forum.getkirby.com/t/limit-number-of-structure-entries/4784 "2016-07-25T15:13:08Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![mxst](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/mxst/32/12448_2.png) [@mxst](https://forum.getkirby.com/u/mxst)\
**Post date:** [July 25, 2016, 3:13pm UTC](https://forum.getkirby.com/t/limit-number-of-structure-entries/4784/1 "2016-07-25T15:13:08Z")

</div>

So I would like to limit the number of entries a structure can have. I tried the documentation but didn’t find anything.

Hope someone can help me

~ Max

---

<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:** [July 25, 2016, 3:27pm UTC](https://forum.getkirby.com/t/limit-number-of-structure-entries/4784/2 "2016-07-25T15:27:10Z")

</div>

Unfortunately, there is no option to limit the number of structure items. You could try to copy the structure field and adapt it to your needs.

There is already a [feature request issue on GitHub](https://github.com/getkirby/panel/issues/876).

---

<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:** [July 25, 2016, 3:39pm UTC](https://forum.getkirby.com/t/limit-number-of-structure-entries/4784/3 "2016-07-25T15:39:41Z")

</div>

Although you can not limit it in the panel, you can limit the number you display in your panel. I often use an information text in the panel to let the user know only the first X entries will be displayed.

You could even go for some custom panel css to show for exemple in red the entries after the nth.

---

<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:** [July 25, 2016, 4:12pm UTC](https://forum.getkirby.com/t/limit-number-of-structure-entries/4784/4 "2016-07-25T16:12:48Z")

</div>

> [@Thiousi](#):
>
> I often use an information text in the panel to let the user know only the first X entries will be displayed.

Please keep in mind, that this will only work correctly, if you don’t sort, shuffle, flip etc. the entries in your template.

---

<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:** [July 25, 2016, 9:52pm UTC](https://forum.getkirby.com/t/limit-number-of-structure-entries/4784/5 "2016-07-25T21:52:44Z")

</div>

As long as this feature is not part of the core, you can achieve it like this:

- copy the structure field and put it into `site/fields`, so that the current field will be overwritten and you don’t have to modify the core code
- make the following changes to /site/fields/structure/structure.php

In line 19, add a new property called limit:

```auto
public $limit = null;

```

Replace the headline function from lines 127ff with the following code

```auto
public function headline() {
    // get entries
    $entries = $this->entries();
   // check if limit is either null or the number of entries less than limit 
    if(!$this->readonly && (is_null($this->limit) || (is_int($this->limit) && $entries->count() < $this->limit))) {
        $add = new Brick('a');
        $add->html('<i class="icon icon-left fa fa-plus-circle"></i>' . l('fields.structure.add'));
        $add->addClass('structure-add-button label-option');
        $add->data('modal', true);
        $add->attr('href', purl($this->model, 'field/' . $this->name . '/structure/add'));

    } else {
      $add = null;
    }

    // make sure there's at least an empty label
    if(!$this->label) {
      $this->label = '&nbsp;';
    }

    $label = parent::label();
    $label->addClass('structure-label');
    $label->append($add);

    return $label;

  }

```

With these modifications, the add button is only shown if there is no limit given or if the limit is greater than the current number of items.

Now you can add the new option in your blueprint:

```auto
events:
    label: Events
    type: structure
    style: table
    limit: 5
    fields:
      title:
        label: Title
        type: text
      text:
        label: Text
        type: text

```

---

<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:** [July 25, 2016, 10:28pm UTC](https://forum.getkirby.com/t/limit-number-of-structure-entries/4784/6 "2016-07-25T22:28:20Z")

</div>

Well that’s simply brilliant ! I’m guessing you submitted it to the core ?

---

<div class="post-metadata">

**Author:** ![lukasbestle](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/lukasbestle/32/11437_2.png) [@lukasbestle](https://forum.getkirby.com/u/lukasbestle)\
**Post date:** [July 26, 2016, 8:04am UTC](https://forum.getkirby.com/t/limit-number-of-structure-entries/4784/7 "2016-07-26T08:04:05Z")

</div>

I am going to make some tests with this for the next release. 🙂

---

<div class="post-metadata">

**Author:** ![mxst](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/mxst/32/12448_2.png) [@mxst](https://forum.getkirby.com/u/mxst)\
**Post date:** [July 26, 2016, 10:02am UTC](https://forum.getkirby.com/t/limit-number-of-structure-entries/4784/8 "2016-07-26T10:02:32Z")

</div>

Thank you very much 🙂

@lukasbestle to include that properly one should prohibit `example.com/panel/site/field/fieldname/structure/add` from working when the limit is reached

---

<div class="post-metadata">

**Author:** ![lukasbestle](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/lukasbestle/32/11437_2.png) [@lukasbestle](https://forum.getkirby.com/u/lukasbestle)\
**Post date:** [July 26, 2016, 10:16am UTC](https://forum.getkirby.com/t/limit-number-of-structure-entries/4784/9 "2016-07-26T10:16:39Z")

</div>

That’s exactly what I thought as well. 🙂

---

<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:** [July 26, 2016, 12:57pm UTC](https://forum.getkirby.com/t/limit-number-of-structure-entries/4784/10 "2016-07-26T12:57:15Z")

</div>

That’s what I thought as well until I found that the readonly option is handled exactly in this way, so I thought I might just use that for a quick solution.

---

<div class="post-metadata">

**Author:** ![lukasbestle](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/lukasbestle/32/11437_2.png) [@lukasbestle](https://forum.getkirby.com/u/lukasbestle)\
**Post date:** [July 26, 2016, 1:55pm UTC](https://forum.getkirby.com/t/limit-number-of-structure-entries/4784/11 "2016-07-26T13:55:03Z")

</div>

Oh, then that’s a bug. I will take a look at it.

---

<div class="post-metadata">

**Author:** ![lukasbestle](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/lukasbestle/32/11437_2.png) [@lukasbestle](https://forum.getkirby.com/u/lukasbestle)\
**Post date:** [July 27, 2016, 4:00pm UTC](https://forum.getkirby.com/t/limit-number-of-structure-entries/4784/12 "2016-07-27T16:00:52Z")

</div>

This feature is now on the develop branch for Kirby 2.3.2. I have also fixed the missing validation for the route, thanks @mxst!

---

<div class="post-metadata">

**Author:** ![plagasul](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/plagasul/32/4199_2.png) [@plagasul](https://forum.getkirby.com/u/plagasul)\
**Post date:** [August 26, 2017, 4:40pm UTC](https://forum.getkirby.com/t/limit-number-of-structure-entries/4784/13 "2017-08-26T16:40:33Z")

</div>

Has this been included into Kirby in the end ?

---

<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 26, 2017, 5:00pm UTC](https://forum.getkirby.com/t/limit-number-of-structure-entries/4784/14 "2017-08-26T17:00:56Z")

</div>

The limit option option works.

---

<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:32pm UTC](https://forum.getkirby.com/t/limit-number-of-structure-entries/4784/15 "2025-02-06T17:32:14Z")

</div>


