Creating and editing categories from the Panel

Hello! I integrated a category section in my blueprints and followed the tutorial on youtube and the documentation for a filterable menu in the php section of this. Now i have two problems.

First, for my filter bar, only the pages from the current pagination get shown, might also be a typo or wrong order.
My php for that looks like this:

    <?php
        $filterBy = get('filter');

        $program = $page
            ->children()
            ->listed()->flip()
            ->when($filterBy, function($filterBy) {
                return $this->filterBy('category', $filterBy, ',');
            })
            ->paginate(20);

            $filters = $program->pluck('category', ',', true);
            $pagination = $program->pagination();
    ?>

Second, is it possible that i let my customer create categories and manage categories from the panel page itself?

Best regards.

Your code looks absolutely correct and should filter all pages (but of course, always return a paginated result).

Yes, you can have a field somewhere where users add categories, and then in your category field query those categories as options: Multiselect | Kirby CMS

1 Like

I will implement the mulsiselect, thanks for this.

Ill try to explain the problem above a bit better, i just saw i misstyped “pages” when i ment “categories”.
I want a filterbar that can show all categories of all pages. However , my filterbar only returns the categories of pages which are shown in the pagination.

My filterbar after the code i posted above looks like this:

                <?php foreach ($filters as $filter) : ?>
                <a href="<?= $page->url() ?>?filter=<?= $filter ?>">
                    <?= $filter ?>
                </a>
                <?php endforeach?>

Thanks for the help!

You don’t have to, you can do the same with the tags field.

1 Like

The problem is the order in your code, because you are only fetching the categories of the already filtered pages:

<?php
        $filterBy = get('filter');
        $programPages =  $page->children()->listed();
        $filters = $programPages->pluck('category', ',', true);
        $program = $programPages
            ->when($filterBy, function($filterBy) {
                return $this->filterBy('category', $filterBy, ',');
            })
            ->paginate(20);

            $pagination = $program->pagination();
    ?>
1 Like