Skip to content

Instantly share code, notes, and snippets.

@Flobin

Flobin/tag.php Secret

Created February 27, 2017 16:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Flobin/08a9c185bea907a5edf7da62e30536fa to your computer and use it in GitHub Desktop.
Save Flobin/08a9c185bea907a5edf7da62e30536fa to your computer and use it in GitHub Desktop.
<?php
// https://getkirby.com/docs/cookbook/tags
return function($site, $pages, $page) {
// fetch the basic set of pages
$projects = page('projects')->children()->visible()->flip();
// fetch the basic set of posts
$blogposts = page('blog')->children()->visible()->flip();
// add the tag filter
if($tag = param('tag')) {
$projects = $projects->filterBy('tags', $tag, ',');
$blogposts = $blogposts->filterBy('tags', $tag, ',');
}
// fetch all tags
$tags = $projects->pluck('tags', ',', false);
$tags += $blogposts->pluck('tags', ',', false);
// apply pagination
$projects = $projects->paginate(10);
$pagination = $projects->pagination();
$blogposts = $blogposts->paginate(10);
$pagination = $blogposts->pagination();
return compact('projects', 'blogposts', 'tags', 'tag', 'pagination');
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment