Hi there,
I’m trying to use a category map as texnixe wrote several times in the forum (1, 2)
My setup is a bit different though: I’m fetching News and Projects from different pages in different categories via a controller (every news item or project can have multiple categories attached to them. This is just one of the six categories):
if($page->uid() == 'strategy') {
$projects = $pages->find('projects')->children()->visible()->filterBy('categories', 'cat_strategy', ',');
$news = $pages->find('news')->children()->visible()->filterBy('categories', 'cat_strategy', ',');
$posts = new Pages(array($projects, $news));
This works, all the items in a specific category get displayed, it doesn’t matter if it’s a news item or a project.
Then I tried to use the code bit from texnixe to show the categories and their blueprint “translation”:
<?php
$categoryMap = c::get('categoryMap');
echo $categoryMap[trim($page->category())];
?>
with something similar in my config:
c::set('categoryMap', array(
'news' => 'News Article',
'architecture' => 'Architecture',
'photography' => 'Photography',
));
But apparently I can’t use an array for trimming. So I tried putting the categories used on an item in an array, use array_intersect, implode, but that’s just me poking around in the dark. I already learned a lot since starting with kirby a little over a year ago, but I still don’t get arrays and I don’t know how to take the array in the config and subtract the categories from the news item or project and show the translation.
Where I want to use it would be on the projects overview page where I tried something like this:
<?php $projects = page('projects')->children()->visible(); ?>
<?php foreach($projects as $project): ?>
<p class="showcase-tags">
<?php
$categoryMap = c::get('categoryMap');
$categories = array($project->categories()->value());
$categoriesFinal = array_intersect($categoryMap, $categories);
dump($categoryMap);
dump($categories);
dump($categoriesFinal);
echo implode(' | ', $categoriesFinal);
?>
</p>
This is the poking around in the dark part, I’m afraid.
I really hope somebody can help me here!
Cheers,
Daniel