# Sorting paginated pages by date

**URL:** <https://discourse.gohugo.io/t/sorting-paginated-pages-by-date/14472>\
**Category:** support\
**Tags:** pagination\
**Created:** [September 28, 2018, 1:31pm UTC](https://discourse.gohugo.io/t/sorting-paginated-pages-by-date/14472 "2018-09-28T13:31:50Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![rhewitt](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/rhewitt/32/332_2.png) [@rhewitt](https://discourse.gohugo.io/u/rhewitt)\
**Post date:** [September 28, 2018, 1:31pm UTC](https://discourse.gohugo.io/t/sorting-paginated-pages-by-date/14472/1 "2018-09-28T13:31:51Z")

</div>

I’m creating a content type of Events. Each event has a `start` and `end` page parameter. I haven’t been able to sort by that page parameter so I tried introducing the `date` variable to try to sort by that without any luck. **Can you help me reverse the order of my events for my list page?**

## Frontmatter

```auto
---
date: 2019-05-03T09:00:00.000Z
start: 2019-05-03T09:00:00.000Z
end: 2019-05-03T12:00:00.000Z
---

```

## Template attempts

```auto
{{ $paginator := .Paginate (where .Data.Pages.ByDate.Reverse "Section" $section) 7 }}
{{ $paginator := .Paginate (where .Data.Pages "Section" $section).ByDate.Reverse 7 }}
{{ $paginator := .Paginate (sort (where .Data.Pages "Section" $section) "start" "asc") 7 }}

```

There are no errors in the terminal, and the order of the events never changed.

---

<div class="post-metadata">

**Author:** ![maiki](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/maiki/32/16384_2.png) [@maiki](https://discourse.gohugo.io/u/maiki)\
**Post date:** [September 28, 2018, 2:54pm UTC](https://discourse.gohugo.io/t/sorting-paginated-pages-by-date/14472/2 "2018-09-28T14:54:05Z")

</div>

Please read [Requesting Help](https://discourse.gohugo.io/t/requesting-help/9132) and share your project’s code, so other may assist.

---

<div class="post-metadata">

**Author:** ![rhewitt](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/rhewitt/32/332_2.png) [@rhewitt](https://discourse.gohugo.io/u/rhewitt)\
**Post date:** [September 28, 2018, 2:55pm UTC](https://discourse.gohugo.io/t/sorting-paginated-pages-by-date/14472/3 "2018-09-28T14:55:27Z")

</div>

> **[USFWS/southeast](https://github.com/usfws/southeast)**
>
> The website source code for the Southeast Region of the U.S. Fish and Wildlife Service - USFWS/southeast

---

<div class="post-metadata">

**Author:** ![zwbetz](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/zwbetz/32/16088_2.png) [@zwbetz](https://discourse.gohugo.io/u/zwbetz)\
**Post date:** [September 28, 2018, 8:27pm UTC](https://discourse.gohugo.io/t/sorting-paginated-pages-by-date/14472/4 "2018-09-28T20:27:18Z")

</div>

Tried cloning your repo but it’s over 7GB so that’s not an option for me.

Try removing `.Data` (_untested_)

```auto
{{ $paginator := .Paginate (where .Pages.ByDate.Reverse "Section" $section) 7 }}

```

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [September 28, 2018, 8:46pm UTC](https://discourse.gohugo.io/t/sorting-paginated-pages-by-date/14472/5 "2018-09-28T20:46:25Z")

</div>

> [@zwbetz](#):
>
> Try removing `.Data` ( _untested_ )

That will be the same.

Most of the variants above all looks correct.

---

<div class="post-metadata">

**Author:** ![pointyfar](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/pointyfar/32/5797_2.png) [@pointyfar](https://discourse.gohugo.io/u/pointyfar)\
**Post date:** [September 29, 2018, 12:40pm UTC](https://discourse.gohugo.io/t/sorting-paginated-pages-by-date/14472/6 "2018-09-29T12:40:24Z")

</div>

Give this a whirl:

```auto
{{ $pages := where .Data.Pages "Section" $section }}

{{ $sorted := $pages.ByParam "start" }}
reverse:
{{ $sorted := ($pages.ByParam "start").Reverse }}

{{ $paginator := .Paginate $sorted 7 }}

```

```auto
{{ $sorted := sort $pages "Params.start" "asc" }}

```

also seems to work.

---

<div class="post-metadata">

**Author:** ![rhewitt](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/rhewitt/32/332_2.png) [@rhewitt](https://discourse.gohugo.io/u/rhewitt)\
**Post date:** [October 1, 2018, 12:06pm UTC](https://discourse.gohugo.io/t/sorting-paginated-pages-by-date/14472/7 "2018-10-01T12:06:46Z")

</div>

It turned out Hugo was rendering the page with a different template than I thought it was using…

Once that was straightened out I used @pointyfair suggestion with success.

```auto
{{ $pages := where .Site.Pages "Section" $section }}
{{ $paginator := .Paginate $pages 7 }}

ul.card-list
  {{ range sort $paginator.Pages "Params.start" "asc" }}
    {{ .Render "summary" }}
  {{ end }}

{{ partial "pagination.html" . }}

```

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [October 1, 2018, 1:08pm UTC](https://discourse.gohugo.io/t/sorting-paginated-pages-by-date/14472/8 "2018-10-01T13:08:05Z")

</div>

You nees to sort them before you paginate them.

---

<div class="post-metadata">

**Author:** ![tubia](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/tubia/32/8827_2.png) [@tubia](https://discourse.gohugo.io/u/tubia)\
**Post date:** [May 31, 2019, 10:11am UTC](https://discourse.gohugo.io/t/sorting-paginated-pages-by-date/14472/9 "2019-05-31T10:11:10Z")

</div>

If I try to use this solution in `_default/list.html` template I get `undefined variable "$section"`.

Is there anything I am missing here?

---

<div class="post-metadata">

**Author:** ![maiki](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/maiki/32/16384_2.png) [@maiki](https://discourse.gohugo.io/u/maiki)\
**Post date:** [June 1, 2019, 2:45am UTC](https://discourse.gohugo.io/t/sorting-paginated-pages-by-date/14472/10 "2019-06-01T02:45:21Z")

</div>


