Menu with filtered items

I want to create filtered items. My first try was to use the function “filterBy”:

<?php foreach ($site->children()->listed()->filterBy('template', '==', 'temp0') as $item): ?>

but i need to exclude more than one entry. My second version has no success:

<?php foreach ($site->children()->listed()->filterBy('template', '==', 'temp0', 'temp1') as $item): ?>

Another approach would be, i have several numbered content folders and i want to show only the items by the folder0 to folder5, or the the folder6 to folder7. The function “filterBy” want only one criteria, but i need the possibility to filter out more than one folder to create a menu.

What can i do?

You can do it like this:

$items = $site->children()->listed()->filterBy('template', 'in', ['template-a', 'template-b']);
foreach ($items as $item) :
  // do stuff

For more filter methods see the docs:

Depending on what you want to achieve exactly, excluding instead of including might be more suitable to prevent long lists of included templates, or using listed vs. unlisted pages, or even a manually built menu.

Thank you, it solved my problem.