I there. I started with kirby a week ago and am pretty happy with all the options kirby offers.
At the moment I stuck at a problem. I have a dynamically generated category- and tag-list in my navigation. For this I created a file in my site/controller-dolswe, which is going through all my articles and analyzes the categories and tags.
<?php
return function ( $site, $pages, $page ) {
$articles = $page->children();
if($page->template() == 'item'){
$articles = $page->parent()->children();
}
$categories = $articles->pluck( 'categories', ',', true );
$tags = $articles->pluck( 'tags', ',', true );
if ( $category = urldecode( param( 'category' ) ) ) {
$articles = $articles->filterBy( 'categories', $category, ',' )->sortBy( 'date' )->flip();
} else {
$articles = $articles->sortBy( 'date' )->flip();
}
if ( $tag = urldecode( param( 'tag' ) ) ) {
$articles = $articles->filterBy( 'tags', $tag, ',' )->flip();
} else {
$articles = $articles->sortBy( 'date' )->flip();
}
return compact( 'articles', 'categories', 'category', 'tags', 'tag' );
};`
In my navigation bar snippet I loaded all existing categories and tags and it works like a charme. Here is a fragment of this snippet:
`<div class="categories" id="kategorien">
<?php foreach ( $categories as $category ) : ?>
<a href="<?php echo url($page->url(), ['params' => ['category' => $category]]) ?>" class="category<?php if ( $category == urlencode( param( 'category' ) ) ) : ?> active<?php endif; ?>" rel="category tag">
<?= $category ?>
</a>
<?php endforeach ?>
</div>
<div class="tags" id="materials">
<?php foreach ( $tags as $tag ) : ?>
<a href="<?php echo url($page->url(), ['params' => ['tag' => $tag]]) ?>" class="tag<?php if ( $tag == urlencode( param( 'tag' ) ) ) : ?> active<?php endif; ?>" rel="category tag">
<?= $tag ?>
</a>
<?php endforeach ?>
</div>`
I really like the concept of loading all categories and tags dynamically. My colleague asked me, if there is an option to influence the sorting of the tags manually. Unfortunately I have no idea how to achieve a manually sorted order without hardcoding my links into the template. Do you have an idea or know a good alternative solution for this?
Thank you very much for your help.