# Showing only top used tags (easy) but sort them alphabetically (how?) instead of byCount

**URL:** <https://discourse.gohugo.io/t/showing-only-top-used-tags-easy-but-sort-them-alphabetically-how-instead-of-bycount/48719>\
**Category:** support\
**Tags:** taxonomy\
**Created:** [March 8, 2024, 6:42pm UTC](https://discourse.gohugo.io/t/showing-only-top-used-tags-easy-but-sort-them-alphabetically-how-instead-of-bycount/48719 "2024-03-08T18:42:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![andr](https://avatars.discourse-cdn.com/v4/letter/a/85f322/32.png) [@andr](https://discourse.gohugo.io/u/andr)\
**Post date:** [March 8, 2024, 6:42pm UTC](https://discourse.gohugo.io/t/showing-only-top-used-tags-easy-but-sort-them-alphabetically-how-instead-of-bycount/48719/1 "2024-03-08T18:42:57Z")

</div>

I am trying to show a list of the 25 most frequently used tags. This can easily be achieved in a taxonomy template like this:

```auto
{{ $tags := (first 25 (.Site.Taxonomies.tags.ByCount)) }}
     {{range $tags }} {{ $cnt := .Count }}
          <span class="w3-tag"><a href={{ .Page.RelPermalink }} title="All pages with tag '{{ .Page.Title }}'">{{ .Page.Title }} ({{ $cnt }})</a></span>
	{{end}}

```

However now the top 25 Tags are in the order of their occurrence. What I am trying now is to add an additional sort onto the limited tags and print them out in alphabetical order.

How is this possible? All my trials with `sort` fail. It seems the `$tags` is already of a type `page.OrderedTaxonomy`. And this seems not to be sortable any more!?

Am I overlooking something?

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [March 8, 2024, 7:47pm UTC](https://discourse.gohugo.io/t/showing-only-top-used-tags-easy-but-sort-them-alphabetically-how-instead-of-bycount/48719/2 "2024-03-08T19:47:56Z")

</div>

```plaintext
{{ range sort (site.Taxonomies.tags.ByCount | first 3) "Page.LinkTitle" "asc" }}

```

---

<div class="post-metadata">

**Author:** ![andr](https://avatars.discourse-cdn.com/v4/letter/a/85f322/32.png) [@andr](https://discourse.gohugo.io/u/andr)\
**Post date:** [March 8, 2024, 8:02pm UTC](https://discourse.gohugo.io/t/showing-only-top-used-tags-easy-but-sort-them-alphabetically-how-instead-of-bycount/48719/3 "2024-03-08T20:02:32Z")

</div>

Thanks so much! This was indeed the solution.  
I only had been trying with all sorts of `"LinkTitle"` / `".LinkTitle"` and various slightly different combinations of those.  
Had been going through the docs for the last 2 hours probably for this problem.

That’s my code now and it is exactly what I need:

```auto
{{ $tags := (first 25 (.Site.Taxonomies.tags.ByCount)) }}
{{range sort $tags "Page.LinkTitle" "asc" }} {{ $cnt := .Count }}
          <span class="w3-tag"><a href={{ .Page.RelPermalink }} title="All pages with tag '{{ .Page.Title }}'">{{ .Page.Title }} ({{ $cnt }})</a></span>
{{end}}

```

---

<div class="post-metadata">

**Author:** ![system](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/system/32/1_2.png) [@system](https://discourse.gohugo.io/u/system)\
**Post date:** [March 10, 2024, 8:03pm UTC](https://discourse.gohugo.io/t/showing-only-top-used-tags-easy-but-sort-them-alphabetically-how-instead-of-bycount/48719/4 "2024-03-10T20:03:22Z")

</div>

Closed on March 10, 2024, 8:03pm UTC

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.
