Sort tagcloud alphabetically or manually?

How can I sort my tags listed in the tagcloud alphabetically? Any way to sort manually so that one specific tag always appears first (and manually set the order of the rest of the tags)?

Here’s the code I have calling the tags list:

  $tags = $page->images()->pluck('tags', ',', true);
  $activetag = kirby()->request()->params()->tag();

  <?php foreach($tags as $tag): ?>
      <a <?php ecco($tag == $activetag, ' class="active"') ?> href="<?php echo url('work/tag:' . $tag)?>">
        <?php echo html($tag) ?>
  <?php endforeach ?>


you can try to sort the array with a php-function. asort is probably the right one.

1 Like