I have this collection of blogposts that I can filter by tag. I want the page to only display the 12 most recent posts (and when filtered the 12 most recent with that active filter of course). This is working fine, however I want to be able to put a CTA after 6 posts and show the other 6 posts after that. I tried doing this with the code below but this way the pagination is not working properly. Page 1 shows as:
- Cards 1-6
- CTA
- Cards 7-12
Page 2 shows as:
- Cards 7-12
- CTA
- Cards 13-18
What would be the best approach for this to work?
Insights controller
<?php
return function ($kirby, $site, $pages, $page) {
$filterBy = get('filter');
$unfiltered = $page->children()->listed();
if ($filterBy) {
$filtered = $unfiltered->filterBy('tag', $filterBy, ',');
} else {
$filtered = $unfiltered;
}
$tags = $unfiltered->pluck('tag', ',', true);
return [
'filterBy' => $filterBy,
'unfiltered' => $unfiltered,
'filtered' => $filtered,
'tags' => $tags
];
};
Insights page template
<!-- Filter -->
<?php snippet('sections/insights/filter', ['tags' => $tags, 'filterBy' => $filterBy]) ?>
<!-- Collection part 1 -->
<?php snippet('sections/insights/cards', ['tags' => $tags, 'filterBy' => $filterBy, 'collection' => $filtered->paginate(6)]) ?>
<!-- CTA -->
<?php snippet('sections/cta') ?>
<!-- Collection part 2 -->
<?php snippet('sections/insights/cards', ['tags' => $tags, 'filterBy' => $filterBy, 'collection' => $filtered->offset(6)->paginate(6)]) ?>
<!-- Pagination -->
<?php snippet('sections/insights/pagination') ?>