HUGO

Pagination Reverse Date Order - Massively Theme

Hi All

I’ve read through a few threads on here re pagination.

Currently i have about 24 posts. They are in date order, and when i change the settings to be 30 posts per page they are in perfect date order. (one long page)

As soon as i reduce that to say 8 per page, and pagination kicks in, the date ordering is off.

I’ve tried to play around with the pagination in /pagination.html and /list.html and no luck so far.

If anyone has any ideas, would be much appreiciated

Please post a link to the public repository for your site. See:
https://discourse.gohugo.io/t/requesting-help/9132

Include a link to the source code repository of your project, because we really need the context of seeing your templates and partials to be able to help you. It is trivial to do a quick git clone on your repo, then run hugo server in your project, to help you out. On the other hand, recreating your code from screenshots, or sort of guessing at it, is not.

If you can’t share your repository for whatever reason, consider creating a dummy repo that you can share, which reproduces the problem you’re experiencing.

2 Likes

Hi, sorry for the delay!

Here is the link to the repo, if any Hugo wizard is able to work out why the pagination doesn’t work!

You just need to change back to 8 posts per page to get the pagination to kick in and see how it doesn’t work.

Cheers

  • Which lines on which files are you changing into what values?
  • What is the behaviour you expect and what is happening instead?

Hi There!

Sorry, i should have been more specific with that.

If you load page now you’ll see one long page of posts, all sorted in date order. This is working as expected.

To recreate the problem, go to file ‘index.html’ on line 6. you can change the number 30 to 8.

Once you’ve changed this and look at the page you’ll see it splits onto 3 or 4 pages.

However, the date ordering then does not work. the posts are no longer in date order and are completely jumbled. I have no idea why this happens.

I have tried:

  • changing the sorting method from date to ‘rating’ and giving each post a rating. This worked on one page but like the date sorting the logic didn’t carry into the pagination.

I believe this is being controlled in ‘pagination.html’.

Any insight would be hugely appreciated.

Change this line:
https://github.com/WillNaylor1994/Test999/blob/master/themes/hugo-theme-massively-master/layouts/index.html#L29

From

{{ $postsPaging := .Paginate  $postsForPaging $postsPageSize }} 

To:

{{ $postsPaging := .Paginate $postsForPaging.ByDate $postsPageSize }}
1 Like

You sir are a true hero.

I have been struggling with that for ages.

Thank you to all for your comments and looking into this. I shall try to read up to understand what’s happened there.

Thanks again.

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