Skip to content

$pages->not()

Returns a Collection without the given element(s)

$pages->not(mixed $keys = null): Kirby\Cms\Collection

Parameters

Name Type Default Description
$keys mixed null any number of keys, passed as individual arguments

Return type

Kirby\Cms\Collection

Parent class

Kirby\Cms\Pages inherited from Kirby\Cms\Collection

Example

Note that you have to pass the full id as parameter:

<h2>All pages except project-b</h2>
<ul>
  <?php foreach($page->children()->not('projects/project-b') as $subpage): ?>
  <li>
    <a href="<?= $subpage->url() ?>">
      <?= $subpage->title()->html() ?>
    </a>
  </li>
  <?php endforeach ?>
</ul>

Pass collection as argument

You can pass a collection as argument as well:

<ul>
  <?php
  $excluded = $page->children()->filterBy('template', 'some_template');
  foreach($page->children()->not($excluded) as $subpage): ?>
  <li>
    <a href="<?= $subpage->url() ?>">
      <?= $subpage->title()->html() ?>
    </a>
  </li>
  <?php endforeach ?>
</ul>

Array of ids, collections or objects as argument

Since 3.4.3

You can also use an array of ids, collections or objects or a mixture of them to exclude from a collection:

An array of ids

$children = $page->index()->listed()->not(['path/to/page-a', 'path/to/page-c', 'path/to/page-non-exists']);

An array of objects

$children = $page->index()->listed()->not([page('path/to/page-a'), page('path/to/page-c')]);

An array of mixed values

$children = $page->index()->not([$page->children()->template('article-video'), page('path/to/page-a')]);