Hi, I create categories from parent page with structure:
category:
label: Categories
type: structure
fields:
cattitle:
label: Title
type: text
catdesc:
label: Content
type: textarea
In subpage, I select categories with checkboxes:
cat:
label: Category
type: checkboxes
#style: table
options: query
query:
fetch: page.parent.category.toStructure
text: "{{ structureItem.cattitle }}"
value: "{{ structureItem.cattitle }}"
In the parent page template, I show the categories and correspondant subpages this way:
<?php $subpages = $page->children()->listed() ;?>
<?php $categories = $subpages->sortBy('cat', 'sort')->pluck('cat', ',', true);?>
<?php foreach ($categories as $category): ?>
<div class="">
<h2><?php echo html($category) ?></h2>
<?php $catlist = $subpages->filterBy('cat', $category, true); ?>
<?php foreach ($catlist as $cat): ?>
<a <?= r($cat->isOpen(), ' class="is-active"') ?> href="<?php echo $cat->url() ?>"><?php echo $cat->title()->html() ?></a>
<?php endforeach ?>
</div>
<?php endforeach ?>
It seems to work corectly, but I can’t sort categories manually. Only asc or desc will work.
So I tried something like this, but does not work, categories titles from structures are correctly shown, but I can’t output nothing from correspondant subpages and I’ve no idea how to do it.
<?php foreach ($page->category()->toStructure() as $category): ?>
<h2><?= $category->cattitle()->html() ?></h2>
<?php $categorylist = $page->children()->filterBy('cat', $category) ?>
<?php foreach ($categorylist as $cat): ?>
<a<?= r($cat->isOpen(), ' class="is-active"') ?> href="<?php echo $cat->url() ?>"><?php echo $cat->title()->html() ?></a>
<?php endforeach ?>
<?php endforeach ?>
Any help is welcome, thank you.