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

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:

{{ $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?

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

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:

{{ $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}}

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