Sorting posts by taxonomy

Since I have a blog full of movie critics, I’d like to sort my posts by the date of the movie itself, not the date of publication. To do so, I have a taxonomy with a year per post and I’d like to sort the posts using this numeric information.

Unless I’m mistaken, there’s no integrated way of doing so. Am I right ?

If so, what would be the best approach ?

Thanks !

See http://gohugo.io/taxonomies/ordering/#ordering-content-within-taxonomies:561853832019df340acf603aaa8ed39a

In your case I guess it maybe makes sense to have publication year both as a taxonomy item and a taxonomy weight.

So for a page about a movie from 2015:

tags = [ “Drama”, “2015” ]
tags_weight = 2015

This way, when you look at the “Drama” list page, it will be ordered by year.

@tatsushid may have a better suggestion.

I thought of that solution, indeed. I hoped to find something simpler (it’s one more information to fill each time) but I guess it would work.

Thanks for taking the time to answer. :slight_smile:

One thing I didn’t think of, is that by default my posts would be sorted by weight, which I don’t want. I only want the weight sorting to be in place in certain places (like archives), and not on the index page.

So, if someone needs the same thing, here’s the code that works to force the listing by publication date :

	{{ range .Data.Pages.ByDate.Reverse }}

Not if you set the taxonomy-specific weight, right?

tag_weight=2015

Oh, I did not realize it was possible ! So, my taxonomy is annee, could I use :

annee_weight = 2015

And then, how should I sort my posts ?

Note that I have only read the documentation on this subject, but

annee_weight=2015 will override the default weight (date) for that taxonomy - so that would affect the default order on the list page (myhost.comt/annee/someannee).

Problem is, I’d like to sort posts on other archive pages (for example /acteurs/gerard-depardieu/) using the taxonomy annee. The idea, basically, is to have movies sorted by year.

But I don’t want this sorting feature on the index page, since it’s not only movies.

I think a standard weight and the code I posted earlier should work.