Skip to content

Kirby 5.0.0

$pages->not()

Returns a Collection without the given element(s)

$pages->not(string|array|object ...$keys): Kirby\Cms\Pages

Parameters

Name Type Default Description
...$keys stringorarrayorobject no default value any number of keys,
passed as individual arguments

Return type

Kirby\Cms\Pages

This method does not modify the existing $pages object but returns a new object with the changes applied. Learn more →

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

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')]);