Displaying tags in the same order as in the front matter

Displaying tags using

{{ range first 1 (.GetTerms "tags") }}{{ .LinkTitle }}{{ end }}

displays the first tag but the first tag in alphabetical order. Is there any way to fetch tags while retaining the ordering in the front matter, perhaps using index?

Edit
Using index this way—

{{ (index (.GetTerms "tags") 0).LinkTitle }}

gives the same result—alphabetic ordering.

Edit 2
Using this—

{{ (index ( .Params.Tags ) 0) }}

does what I want, but I lose all other capabilities of taxonomies.

Which capabilities is it you are losing?

You could combine your last snippet with a .GetPage:

{{ if isset .Params "tags" }}
  {{ $tag := (index ( .Params.tags ) 0) }}
  {{ $tagpage := site.GetPage (print "tags/" $tag)}}

  {{ $tagpage.Permalink }} etc
{{ end }}

Thanks.

I was referring to losing capabilities like referencing taxonomy term metadata, permalinks etc. but I suppose I can work around them as in your code.

Still, is there no way to have Hugo not reorder tags unless specified? I think this would make quite a sensible default method of functioning.

You might want to follow this issue.

1 Like

Oh, that’s great. Thanks very much.