I made it possible to tag each post,
On the Photography page, I made sure that all of the tags I created appear.
But I only want tags with the same name to appear once.
Even if I write it several times, can I have the same name appear only once?
<div class="category-box">
<span>Year</span>
<ul class="filter option-set" data-filter-group="content">
<?php foreach ($page->children()->listed() as $product): ?>
<?php foreach ($product->yeartags()->split( ) as $ytags): ?>
<li class="<?= $ytags ?>">
<a href="#" data-filter-value=".<?= $ytags ?>">
<span class="tags_img"></span>
<span class="tags_text"><?= $ytags ?></span>
</a>
</li>
<?php endforeach ?>
<?php endforeach ?>
</ul>
What you want to do instead of looping through all pages and then through all tags is pluck the tags from the pages:
$tags = $page->children()->listed()->pluck('yeartags', ',', true);
The third parameter ($unique) makes sure that each tag only appears once. The result is an array of tags.
1 Like
Thank you for your answer!!!
I think this is the answer I was looking for!
Could you give me a more specific example of how to write it?
I donβt know how to write as you told me.
<?php foreach($page->children()->pluck('yeartags') as $title): ?>
<li><?= html($title) ?></li>
<?php endforeach ?>
<?php $ytags = $page->children()->listed()->pluck('yeartags', ',', true); ?>
<ul class="filter option-set" data-filter-group="content">
<?php foreach ($ytags as $ytag): ?>
<li class="<?= $ytag ?>">
<a href="#" data-filter-value=".<?= $ytag ?>">
<span class="tags_img"></span>
<span class="tags_text"><?= $ytag ?></span>
</a>
</li>
<?php endforeach ?>
1 Like