Hello everyone,
I have a tagcloud that lists all of the tags used in the children items of two main pages.
I also list the count of the items that a tag has -
e.g. Development (3 items), Travel (1 item), Cars (5 items), using this:
$count = $pages->children()->filterBy('tags', $tag)->count();
All works good.
Unfortunately if I add an item that uses more than one tag, all of the tags that are used for this item get a wrong count - which is the real count number minus one item ($count-1).
e.g.:
I have this:
Development (3), Travel (1), Cars (5)
I add a new item that has all of the tags above and I get:
Development (3), Travel (1), Cars (5)
instead of incremented count values:
Development (4), Travel (2), Cars (6)
Do you have any idea why this happens?
Thanks a lot!
Joro
texnixe
November 30, 2017, 12:50pm
2
Sounds like some sort of (browser) caching problem rather than anything else?
Hm, I donβt think itβs a caching issue, since I am using a cache-buster and I just tried in another browser
texnixe
November 30, 2017, 12:57pm
4
Can you provide more code context? Where do you get the tag from? Where do you calculate the tag count?
Here is the full tagcloud.php snippet that I call in header.php:
<?php
$tags = $pages->children()->visible()->pluck('tags', ',', true);
?>
<ul class="tags">
<?php foreach($tags as $tag):
$count = $pages->children()->filterBy('tags', $tag)->count();
?>
<li>
<?= html($tag) ?>
<strong><?= $count ?></strong>
</li>
<?php endforeach ?>
</ul>
texnixe
November 30, 2017, 1:54pm
6
If you change your filterBy()
condition, it should work:
$count = page('projects')->children()->filterBy('tags', '*=', $tag)->count();
or
$count = page('projects')->children()->filterBy('tags', $tag, ',')->count();
2 Likes
Whoa, this works like a charm! Thanks a million, Sonja