So I currently have a tag cloud working properly, but I’m trying to figure out a way to display a limited number sorted by popularity. Here’s my controller for dealing with tags…
I did take a look at that thread, but it doesn’t cover how to limit tags. You can limit pages, but that would omit some tags from the popularity count.
with a dynamic number; the number of tag types (in my case categories). When i run this now i get errors if i can’t fill the quota. In this case “3”. Example: if i have only one category i get 2 following errors.
how i’m using this code (below)
<?php
// get all categories from subpages of 'twigs' page
$categories = page('blog')->children()->visible()->pluck('categories', ',', true);
// get counts for all categories as a measure of popularity
$categories = array_map(function($category) {
$count = page('blog')->children()->visible()->filterBy('categories', $category, ',')->count();
return array('name' => $category, 'count' => $count);
}, $categories); ?>
<ul>
<?php for($x = 1; $x <= 6; $x++) { ?>
<li>
<?php echo ucwords($categories[$x]['name']).' ('.$categories[$x]['count'].')<br>'; ?>
</li>
<?php } ?>