How to exclude articles that have already shown up on a page

Hi there,
I’m banging my head a little over a problem - I have a blog page (Kirby 2) that allows editors to pull out a few different posts to ‘feature’ at the top of the page, then I want to output the rest of the posts below, excluding the ones that have already been ‘featured’.

So I am managing to output a collection of pages that have already shown up by adding to a ‘pages’ variable i.e.

<?php $already = pages(); ?>

Then in my ‘foreach’ loops I do:

<?php $already = $already->merge($featureitem->post()->pages(',')); ?>

This seems to make a nice list when I ‘echo’ it. The problem comes when I’m trying to exclude these posts from the subsequent list of all other articles. I’ve tried a few variations around:

<?php $articles = $page->children()->visible()->flip()->filterBy('id', 'not in', $already); ?>

But nothing seems to work… any suggestions?

Thanks very much,
Rach

Where/how are the featured items defined?

They are defined by a ‘structure’ in the panel - people can choose whether to have a featured series or a featured article and as many as they like…

Full code (sorry, it’s long!)

<!-- FEATURES -->
<?php $features = $page->features()->toStructure(); ?>
<?php $already = pages(); ?>
<?php if($features->count()): ?>
<?php foreach($features as $featureitem): ?>

<!-- FEATURED POSTS-->
<?php if($featureitem->kind() == 'post'):?>
  <div class="inner">
    <p class="lozenge"><?= $featureitem->lozenge()->html(); ?></p>
  </div>
  <ul class="newsfull outer">

    <?php $already = $already->merge($featureitem->post()->pages(',')); ?>
    <?php foreach($featureitem->post()->pages(',') as $feature): ?>

      <li class="newssnippet inner">
        <a href="<?= $feature->url() ?>">
          <?php if($feature->featuredimage()->isNotEmpty()): ?>
            <figure class="newsimage small-end-spaced">
              <img src="<?= $feature->featuredimage()->toFile()->resize(250)->url(); ?>" alt="" />
            </figure>
          <?php endif; ?>
          <div class="newstext">
            <h3 class="ash4"><?= $feature->title()->kirbytextRaw(); ?></h3>
            <?php if($feature->featuredintro()->isNotEmpty()): ?>
              <?= $feature->featuredintro()->kirbytext(); ?>
            <?php endif; ?>
          </div>
        </a>
      </li>
    <?php endforeach; ?>
  </ul>
<?php endif; ?>



<!-- FEATURED SERIES -->
<?php if($featureitem->kind() == 'series'):?>
  <?php foreach($featureitem->series()->pages(',') as $featuredcategory): ?>
    <div class="outer colourway1">
      <div class="standard">
        <p class="lozenge"><?= $featureitem->lozenge()->html(); ?></p>
        <h2><?= $featuredcategory->title(); ?></h2>
        <?php if($featuredcategory->shortintro()->isNotEmpty()): ?>
          <?= $featuredcategory->shortintro()->kt(); ?>
        <?php endif; ?>
      </div><!--/inner-->
      <ul class="newsfull outer">
        <?php $catarticles = page('news')->children()->visible()->filterBy('categories', '*=', $featuredcategory)->flip(); ?>
        <?php $already = $already->merge($catarticles); ?>
        <?php foreach($catarticles as $catarticle): ?>
          <li class="newssnippet inner">

            <a href="<?= $catarticle->url() ?>">

              <?php if($catarticle->featuredimage()->isNotEmpty()): ?>
                <figure class="newsimage small-end-spaced">
                  <img src="<?= $catarticle->featuredimage()->toFile()->resize(250)->url(); ?>" alt="" />
                </figure>
              <?php endif; ?>
              <div class="newstext">
                <h3 class="ash4"><?= $catarticle->title()->kirbytextRaw(); ?></h3>
                  <?php if($catarticle->featuredintro()->isNotEmpty()): ?>
                    <?= $catarticle->featuredintro()->kirbytext(); ?>
                  <?php endif; ?>
              </div>
            </a>
          </li>
        <?php endforeach; ?>
      </ul>
    </div><!--/outer-->
  <?php endforeach; ?>
<?php endif; ?>

<?php endforeach; ?>

<div class="inner">
   <h2>Everything else that's been going on!</h2>
</div>
<?php endif; ?>


<?php $articles = $page->children()->visible()->flip()->filterBy('id', 'not in', $already); ?>

Ok, that’s really a bit complicated, I thought maybe there was an easier way to create your $already collection.

But actually getting the rest is quite simple:

<?php $articles = $page->children()->visible()->not($already) ->flip() ?>

Ah brilliant, I didn’t know you could do ->not()! Thanks very much!