Tag Cloud with multiple page templates

Hey all,

I’m trying to use the Kirby tagcloud plugin to make one giant page of tags, prioritized by popularity and with a count. I’m close to a solution, except the tagcloud plugin seems to only want to pull from one page template. Ideally I’d love it if I could give it multiple templates to pull tags from.

Here’s what I’ve got so far…

<?php $tagcloud = tagcloud(page('episode')) ?>
  <article class="full">
    <ul class="tagcloud episode-tags">
      <?php foreach($tagcloud as $tag): ?>
      <li>
        <?php $x = 0; ?>
        <?php $tagmatches = $site->grandChildren()->filterBy('template','episode')->filterBy('tags', $tag->name(), ','); ?>
        <?php foreach($tagmatches as $tagmatch): $x = $x+1; ?>
        <?php endforeach ?>
        <a <?php if ($x > 1): ?> href="<?php echo url::home() ?>/find/tag:<?php echo rawurlencode($tag->name()) ?>" <?php endif ?>><?php echo trim($tag->name()) ?> (<?php echo $x; ?>)</a>
      </li>
      <?php endforeach ?>
    </ul>
  </article>

…which gives me this result.

That’s great, but I’d like to have the tagcloud function go through the ‘blog’ and ‘other-projects’ templates as well as episode. On a whim, I’ve tried several variants of <?php $tagcloud = tagcloud(pages('episode', 'blog', 'other-projects) ?>, but those attempts just break the page.

Look here in the Tagcloud section: http://getkirby.com/docs/solutions/blog/tags

// fetch all tags
$tags = $page->children()->visible()->pluck('tags', ',', true);

Hey distantnative,

Thanks, I did try the pluck() option, except that sacrificed the ability to sort the tags based on popularity, which I didn’t really want to give up.

Maybe then something like:

$tags = page('episode')->children()->pluck('tags', ',', true);
$tags = array_map(function($tag) { 
  $count = page('episode')->children()->filterBy('tags', $tag, ',')->count();
  return array('name' => $tag, 'count' => $count);
}, $tags);