# Sorting by \`.Page.Weight\` on \`.Site.Taxonomies\`

**URL:** <https://discourse.gohugo.io/t/sorting-by-page-weight-on-site-taxonomies/39832>\
**Category:** support\
**Created:** [August 4, 2022, 8:11pm UTC](https://discourse.gohugo.io/t/sorting-by-page-weight-on-site-taxonomies/39832 "2022-08-04T20:11:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![AlanBreck](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/alanbreck/32/11694_2.png) [@AlanBreck](https://discourse.gohugo.io/u/AlanBreck)\
**Post date:** [August 4, 2022, 8:11pm UTC](https://discourse.gohugo.io/t/sorting-by-page-weight-on-site-taxonomies/39832/1 "2022-08-04T20:11:02Z")

</div>

I’m attempting to list the categories used for a given section using the following snippet:

```auto
{{ range sort (where .Site.Taxonomies.category ".Page.Section" .Section).Alphabetical "Page.Weight" "asc" }}
...
{{ end }}

```

However, since not all of my categories have a `weight` param assigned, the weight is `<nil>` which sorts above `weight = 1`. Is there a way around this?

My workaround is to use DESC and invert the assigned weights.

---

<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:** [August 5, 2022, 6:14pm UTC](https://discourse.gohugo.io/t/sorting-by-page-weight-on-site-taxonomies/39832/2 "2022-08-05T18:14:23Z")

</div>

Given this structure:

```nohighlight
content
└── post/
    ├── _index.md
    ├── post-1.md (weight = 2)
    ├── post-2.md (weight = 1)
    └── post-3.md (weight is not assigned)

```

The sequence when sorted by weight (ascending) will be:

```auto
Post 2
Post 1
Post 3

```

If you want pages without weights to appear first on the list:

content/post/\_index.md

```auto
+++
title = 'Posts'
date = 2022-08-05T11:07:22-07:00
draft = false
[cascade]
  weight = -1000
+++

```

---

<div class="post-metadata">

**Author:** ![AlanBreck](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/alanbreck/32/11694_2.png) [@AlanBreck](https://discourse.gohugo.io/u/AlanBreck)\
**Post date:** [August 5, 2022, 6:38pm UTC](https://discourse.gohugo.io/t/sorting-by-page-weight-on-site-taxonomies/39832/3 "2022-08-05T18:38:37Z")

</div>

Those sorting rules don’t seem to apply here, though, as categories with no assigned weight already rank at the top. I suppose I could still cascade a weight to solve this, but I’m just wondering if it’s expected that `nil` would sort above 1 in my specific use case.

---

<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:** [August 6, 2022, 5:28pm UTC](https://discourse.gohugo.io/t/sorting-by-page-weight-on-site-taxonomies/39832/4 "2022-08-06T17:28:27Z")

</div>

> [@AlanBreck](#):
>
> Those sorting rules don’t seem to apply here

I would need to see your project repository to understand what is happening here.
