I have to show all tags

Hi, I am making index page now.


i want to make like this…
and there is 5 tags as you can see… I need to load all tags.

so first I load every title. and I made controllers like this:

<?php
return function($seallist) {
    $seallist = page('works');
    // fetch the basic set of pages
    $articles = $seallist->children()->listed()->flip();

    // fetch all tags
    $tags = $articles->pluck('tags', ',', true);

    // add the tag filter
    if($tag = param('tag')) {
        $articles = $articles->filterBy('tags', $tag, ',');
    }

    // apply pagination
    $articles   = $articles->paginate(10);
    $pagination = $articles->pagination();

    return compact('articles', 'tags', 'tag', 'pagination');

};

and this is my template… :

<?php snippet('header') ?>

<main class="wrapper-content">
    <?php if ($seallist = page('works')): ?>
            <?php foreach ($seallist->children() as $item): ?>
                <a href="<?= $item->url() ?>"><?= $item->engtitle() ?></a><br>
            <?php endforeach ?><br>

            <ul class="tags">
                <?php foreach($tags as $tag): ?>
                <li>
                <a href="<?= url($seallist->url(), ['params' => ['tag' => $tag]]) ?>">
                    <?= html($tag) ?>
                </a>
                </li>
                <?php endforeach ?>
            </ul>
    <?php endif ?>
</main>

<?php snippet('footer') ?>


but with this code, I can load every title but can not load tags…
could you help me…?
regards,

You mean why they are not filtered?

Because you are not using the variables that you defined in your controller but you redefine your items, so the controller with the filter has no effect whatsoever.


<main class="wrapper-content">
    <?php if ($seallist = page('works')): ?>
            <?php foreach ($articles as $item): ?>
                <a href="<?= $item->url() ?>"><?= $item->engtitle() ?></a><br>
            <?php endforeach ?><br>

            <ul class="tags">
                <?php foreach($tags as $tag): ?>
                <li>
                <a href="<?= url($seallist->url(), ['params' => ['tag' => $tag]]) ?>">
                    <?= html($tag) ?>
                </a>
                </li>
                <?php endforeach ?>
            </ul>
    <?php endif ?>
</main>

thank you very much!
but i mean… I can not load all the tags…
I just want to load every tags but when I use this code, they display nothing…

You mean this list doesn’t output anything?

Otherwise, please be more specific what you are missing.

yes…!


I need to load 5 tags, client, status, year, typology01,02…

and I want to load to display those tags like this:

but I can not load…
I was able to load it, but the items are listed as duplicates…
I want to put items with “type:tags” in the sidebar and use them as categories.
my final goal is… when you click on the tags in the sidebar, I want the corresponding items to be highlighted. But now I can’t even load the tags.

thank you for helping me…

I see, you mean 5 different fields.

But then you need to get them by their field names.

$years  = $articles->pluck('year', ',', true);
$clients = $articles->pluck('client', ',', true);
// etc.

oh!! thank you!!
like this…?:

<?php
return function($seallist) {
    $seallist = page('works');
    // fetch the basic set of pages
    $articles = $seallist->children()->listed()->flip();

    // fetch all tags
    
    $years  = $articles->pluck('year', ',', true);
    $clients = $articles->pluck('client', ',', true);
    $typology01s = $articles->pluck('typology01', ',', true);
    $typology02s = $articles->pluck('typology02', ',', true);
    $statuss = $articles->pluck('status', ',', true);

    // add the tag filter
    if($year = param('year')) {
        $articles = $articles->filterBy('tags', $year, ',');
    }

    // apply pagination
    $articles   = $articles->paginate(10);
    $pagination = $articles->pagination();

    return compact('articles', 'tags', 'tag', 'pagination');
};


but they said : Undefined variable $years…

<ul class="tags">
                <?php foreach($years as $year): ?>
                <li>
                <a href="<?= url($year->url(), ['params' => ['year' => $year]]) ?>">
                    <?= html($year) ?>
                </a>
                </li>
                <?php endforeach ?>
            </ul>

Because you defined the new variables, but are not passing them to the template in the return statement.

could you teach… how can I make return statement…?
:sob::sob::sob:

replace

with

    return compact('articles', 'years', 'clients', 'typology01s',  'typology02s', 'statuss', 'pagination');

wow!!! thanks!!! :pray: :blush: :relaxed: :star_struck: :heart_eyes:

I am so sorry… but one last thing…

I repeat this for 5 tag:

<ul class="tags-status">
                <?php foreach($statuss as $status): ?>
                <li>
                <a href="<?= url($sealindex->url(), ['params' => ['status' => $status]]) ?>">
                    <?= html($status) ?>
                </a>
                </li>
                <?php endforeach ?>
            </ul><br>

and this is controllers:

<?php
return function($seallist) {
    $seallist = page('works');
    // fetch the basic set of pages
    $articles = $seallist->children()->listed()->flip();

    // fetch all tags

    $statuss = $articles->pluck('status', ',', true);
    $typology01s = $articles->pluck('typology01', ',', true);
    $typology02s = $articles->pluck('typology02', ',', true);
    $clients = $articles->pluck('client', ',', true);
    $years  = $articles->pluck('year', ',', true);

    // add the tag filter
    if($status = param('status')) {
        $articles = $articles->filterBy('tags', $status, ',');
    }

    if($typology01 = param('typology01')) {
        $articles = $articles->filterBy('tags', $typology01, ',');
    }

    if($typology02 = param('typology02')) {
        $articles = $articles->filterBy('tags', $typology02, ',');
    }

    if($client = param('client')) {
        $articles = $articles->filterBy('tags', $client, ',');
    }

    if($year = param('year')) {
        $articles = $articles->filterBy('tags', $year, ',');
    }

    // apply pagination
    $articles   = $articles->paginate(10);
    $pagination = $articles->pagination();

    return compact('articles', 'years', 'clients', 'typology01s',  'typology02s', 'statuss', 'pagination');
};


every tags is working super nice but "status"is… just display “listed”.
and

<a href=“<?= url($"here"->url(), ['params' => ['status' => $status]]) ?>”>
<?= html($status) ?>

in “here”, What should I enter? Now it just comes out the whole page…

thank you very much…!

The problem is your field name, because it clashes with Kirby’s $page->status() method.

The easiest would be to rename that field.

Thank you so much!! I didn’t know that…
and…

<a href=“<?= url($"here"->url(), ['params' => ['status' => $status]]) ?>”>
<?= html($status) ?>

in “here”, What should I enter? Now it just comes out the whole page…
also when I put sortBy option… they said "Call to a member function sortBy() on array
"…

thank you so…much…!

The same as for the other lists. Although I wonder why you don’t just use $page given that you seem to be on the works page.

ahh because this is index page and in here… I load "works"page…
I put $sealindex but they make link like this:…/works/client:Shinsegae
and display every content…
and When I put sortBy option… they said "Call to a member function sortBy() on array…

Whatever the index page is (home template?), but yes, then you have to use the page helper as you did when you define

($seallist = page('works')): ?

Look at your filters, they all filter by a tags field, not your field names. That cannot possibly work.