hi,
here is the way i do what i think you're describing, easy for me and easy for the client too
maybe it could be useful and sort of adaptable for your structure
i put all this in a code block, easier to comment 🙂
/*
as it is a multilingual website, i need an easy way to display the tags in various languages
it would work for a one language wensite and it make easy for the client to add a new category
without going anywhere else than in the pages tree
- a page with a template blog_cats without file
- chhildren of this page with a blog_cat template (no file needed either)
- for the blog article pages a page reference field - pages multiple array, every article can belong to several categories
on top of the blog page (with url segments allowed)
*/
// first i retreive the categories in the user language
// 1122, i'm sure you guessed, being the blog_cats page
$cats = $pages->find('parent=1122, template=blog_cat');
$cats_name = array();
foreach ($cats as $c) {
$cats_name[] = $c->name;
}
// then i check if there is an url segment
$zcat = isset($input->urlSegment1) ? $input->urlSegment1 : '';
// if not
if ( $zcat == '') {
$arts = $pages->find('template=blog_article, sort=-date_date, limit=6');
$total = $pages->count('template=blog_article, sort=-date_date, limit=6');
}
// if yes
else {
// yes, being paranoid i first check the url segment is in the cats array above, else... 404
// well, if it were my website o would go for a die() but clients usually need to be a bit more diplomatic :)
if ( ! in_array($zcat, $cats_name) ) throw new Wire404Exception();
$arts = $pages->find('template=blog_article, artcats%='.$zcat.', sort=-date_date, limit=6');
$total = $pages->count('template=blog_article, artcats%='.$zcat.', sort=-date_date, limit=6');
}
of course, easy peasy to set a raw of butttons/links to select a category on top of the blog page using the $cats array retreived above (i like when things are easy :D)
<div class="top_cat_wrapper">
<a href="<?= $page->url; ?>" class="blog_cat_butt<?php if($zcat == '') echo ' selected'; ?>">*</a>
<?php foreach($cats as $bc): ?>
<a href="<?= $page->url.$bc->name; ?>" class="blog_cat_butt<?php if($zcat != '' && $zcat == $bc->name) echo ' selected'; ?>"><?= $bc->title; ?></a>
<?php endforeach; ?>
</div>
in case it could be useful
have a nice day