Skip to content

Can you paginate on an object on its keys and also create pages of the results? #3681

Answered by dwkns
tucker-m asked this question in Q&A
Discussion options

You must be logged in to vote

You actually need to create a flattened chunked array of your posts for each author :

[{
  authorName: "bob",
  pageNumber: 0,
  totalPages: 2,
  pageData: ['post-1','post-2'] 
},{
  authorName: "bob",
  pageNumber: 1,
  totalPages: 2,
  pageData: ['post-3'] 
},{
  authorName: "alice",
  pageNumber: 0,
  totalPages: 2,
  pageData: ['post-4','post-5'] 
},{
  authorName: "alice",
  pageNumber: 1,
  totalPages: 2,
  pageData: ['post-6'] 
}
...
]

And then paginate that with something like:

---
pagination:
  data: collections.authorsPosts
  size: 1
  alias: author
permalink: /authors/{{ author.authorName }}/{% if author.pageNumber %}{{ author.pageNumber + 1 }}/{% endif %}
---
<h1>Author: {{ au…

Replies: 3 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@tucker-m
Comment options

@dwkns
Comment options

Answer selected by tucker-m
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants