# Checkbox items as menu items

**URL:** <https://forum.getkirby.com/t/checkbox-items-as-menu-items/3670>\
**Category:** Questions\
**Tags:** v2\
**Created:** [March 23, 2016, 1:51pm UTC](https://forum.getkirby.com/t/checkbox-items-as-menu-items/3670 "2016-03-23T13:51:31Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![blows](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/blows/32/5241_2.png) [@blows](https://forum.getkirby.com/u/blows)\
**Post date:** [March 23, 2016, 1:51pm UTC](https://forum.getkirby.com/t/checkbox-items-as-menu-items/3670/1 "2016-03-23T13:51:32Z")

</div>

Continuing the discussion from [Problem with custom menu](https://forum.getkirby.com/t/problem-with-custom-menu/3233/4):

> [@Problem with custom menu](https://forum.getkirby.com/t/problem-with-custom-menu/3233/4):
>
> So you basically want to include more items in your menu that come from a structure field instead of the subpages?

Hello,

I’m looking to achieve what’s been quoted above - and would appreciate a pointer in how to approach this.

If the file structure is:  
Projects

- Project (Check box categories A, B)
- Project (Check box categories B, C)
- Project (Check box categories A, C)

How do you create a menu structure where A, B, and C are sub-menu items of ‘Projects’, each displaying all projects in their category?

---

<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:** [March 23, 2016, 2:40pm UTC](https://forum.getkirby.com/t/checkbox-items-as-menu-items/3670/2 "2016-03-23T14:40:43Z")

</div>

That would be something like this, although this solution doesn’t relate to the quote:

```auto
<?php $projects = page('projects')->children()->visible(); ?>

<ul>
  <?php foreach($projects->pluck('categories', ',', true) as $category): ?>
  <li>
    Category <?php echo $category ?>:
    <ul>
      <?php foreach($projects->filterBy('categories', $category, ',') as $project): ?>
      <li><a href="<?php echo $project->url() ?>"><?php echo $project->title() ?></a></li>
      <?php endforeach ?>
    </ul>
  </li>
  <?php endforeach ?>
</ul>

```

This example assumes that each project has a `category` field that looks like this:

```nohighlight
Categories: A, B

```

---

<div class="post-metadata">

**Author:** ![blows](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/blows/32/5241_2.png) [@blows](https://forum.getkirby.com/u/blows)\
**Post date:** [March 23, 2016, 4:04pm UTC](https://forum.getkirby.com/t/checkbox-items-as-menu-items/3670/3 "2016-03-23T16:04:17Z")

</div>

Thank you for this. The solution highlights that I didn’t phrase my question quite as intended.

I think I mean “How do you create a menu structure where A, B, and C are sub-menu items of ‘Projects’, each linking to a page displaying all projects in their category?”

Projects

- A
- B
- C

---

<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:** [March 23, 2016, 4:34pm UTC](https://forum.getkirby.com/t/checkbox-items-as-menu-items/3670/4 "2016-03-23T16:34:20Z")

</div>

All you need is to superpose the main menu structure then:

```auto
<nav class="menu">
  <ul>
    //get all main pages
    <?php foreach($pages->visible() as $p): ?>
      <li>
        <?php echo $p->title() ?>
        //check if page is projects page
        <?php if($p->is('projects')): ?>
          //create submenu for categories
          <ul class="category-submenu">
            <?php $projects = $p->children()->visible(); ?>
            <?php foreach($projects->pluck('categories', ',', true) as $category): ?>
              <li><?php echo $category ?>
                //create submenu for Project pages for each category
                <ul>
                  <?php foreach($projects->filterBy('categories', $category, ',') as $project): ?>
                    <li><a href="<?php echo $project->url() ?>"><?php echo $project->title() ?> </a></li>
                  <?php endforeach ?>
                </ul>
              </li>
            <?php endforeach ?>
          </ul>
        <?php endif ?>
      </li>
    <?php endforeach ?>
  </ul>
</nav>

```

---

<div class="post-metadata">

**Author:** ![blows](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/blows/32/5241_2.png) [@blows](https://forum.getkirby.com/u/blows)\
**Post date:** [March 23, 2016, 8:58pm UTC](https://forum.getkirby.com/t/checkbox-items-as-menu-items/3670/5 "2016-03-23T20:58:43Z")

</div>

Hmm, this is giving a long error, which says:

> Fatal error: Uncaught TypeError: Argument 1 passed to PageAbstract::is() must be an instance of Page, string given, called in …/site/snippets/menu.php on line 20 and defined in …/kirby/core/page.php:768 Stack trace: #0 …/site/snippets/menu.php(20): PageAbstract-\>is(‘projects’) #1 …/kirby/toolkit/lib/tpl.php(22): require(‘…’) #2 …/kirby/helpers.php(13): Tpl::load(‘…’, Array, false) #3 …/site/snippets/header.php(23): snippet(‘menu’) #4 …/kirby/toolkit/lib/tpl.php(22): require(‘…’) #5 …/kirby/helpers.php(13): Tpl::load(‘…’, Array, false) #6 …/site/templates/projects.php(1): snippet(‘header’) #7 …/kirby/toolkit/lib/tpl.php(22 in …/kirby/core/page.php on line 768

Edited out my file structure with “…”

Line 20 is `<?php if($p->is('projects')): ?>`

---

<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:** [March 23, 2016, 9:06pm UTC](https://forum.getkirby.com/t/checkbox-items-as-menu-items/3670/6 "2016-03-23T21:06:19Z")

</div>

Oh, yes, my bad, should be:

```auto
<?php if($p->is(page('projects'))): ?>

```

---

<div class="post-metadata">

**Author:** ![blows](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/blows/32/5241_2.png) [@blows](https://forum.getkirby.com/u/blows)\
**Post date:** [March 23, 2016, 9:16pm UTC](https://forum.getkirby.com/t/checkbox-items-as-menu-items/3670/7 "2016-03-23T21:16:33Z")

</div>

Ah, that fixed it, thank you!

This gives this kind of menu structure:

Projects

- Category A  
– Project A B  
– Project A C
- Category B  
– Project A B  
– Project B C
- Category C  
– Project A C  
– Project B C  
Other Menu Item 1  
Other Menu Item 2  
Other Menu Item 3

Is it possible to have it so the structure is this:

Projects

- Category A
- Category B
- Category C  
Other Menu Item 1  
Other Menu Item 2  
Other Menu Item 3

Where following the link from ‘Category X’ would take you to the projects page and only display the projects in that category?

I was thinking of using something like the Metafizzy Isotope, but am not sure how to integrate that in this way?

---

<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:** [March 23, 2016, 9:27pm UTC](https://forum.getkirby.com/t/checkbox-items-as-menu-items/3670/8 "2016-03-23T21:27:49Z")

</div>

The menu is rather simple. Simply take out the subsubmenu and add a link to the category:

```auto
<nav class="menu">
  <ul>
    <?php foreach($pages->visible() as $p): ?>
      <li>
        <?php echo $p->title() ?>
        
        <?php if($p->is(page('projects'))): ?>
          <ul class="category-submenu">
            <?php $projects = $p->children()->visible(); ?>
            <?php foreach($projects->pluck('categories', ',', true) as $category): ?>
              <li><a href="<?php echo $p->url() . '/category:' . $category ?>"><?php echo $category ?></a></li>
            <?php endforeach ?>
          </ul>
        <?php endif ?>
      </li>
    <?php endforeach ?>
  </ul>
</nav>

```

The filter would work just like the [tag example](https://getkirby.com/docs/solutions/blog/tags), just with the `category` field instead of `tag`.

---

<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:** [March 23, 2016, 9:28pm UTC](https://forum.getkirby.com/t/checkbox-items-as-menu-items/3670/9 "2016-03-23T21:28:53Z")

</div>

You could use a param like, e.g. `category:categoryA` and then filter by that param in your controller:

```auto
<?php foreach($projects->pluck('categories', ',', true) as $category): ?>
   <li>
      <a href="<?php echo page('projects')->url() . '/category:' . $category ?>"><?php echo $category ?></a>               
  </li>
<?php endforeach ?>

```

Edit: Lukas beat me to it.

---

<div class="post-metadata">

**Author:** ![blows](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/blows/32/5241_2.png) [@blows](https://forum.getkirby.com/u/blows)\
**Post date:** [March 23, 2016, 9:48pm UTC](https://forum.getkirby.com/t/checkbox-items-as-menu-items/3670/10 "2016-03-23T21:48:28Z")

</div>

Brilliant, I understand now!  
Thank you both for your help, and pointing me towards the Tags page in the docs - a treasure trove of information.

---

<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:59pm UTC](https://forum.getkirby.com/t/checkbox-items-as-menu-items/3670/11 "2025-02-06T16:59:55Z")

</div>

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


