-
-
Notifications
You must be signed in to change notification settings - Fork 361
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to display a fixed number of posts per page (i.e. pagination) #16
base: master
Are you sure you want to change the base?
Conversation
43bbb96
to
a366614
Compare
a366614
to
a37b74e
Compare
a37b74e
to
b59d1fe
Compare
Hi, wondering what you are thinking about merging this - I'm interested in using this functionality! Tnx |
Here is the background story of all these pull requests: https://yihui.name/en/2017/09/pull-requests-as-a-teaching-tool/ |
Cool. Thanks. |
b59d1fe
to
a8f4b53
Compare
a8f4b53
to
91dbac3
Compare
Given that
Instead of this:
Can you advise what changes should be made to |
91dbac3
to
8b68b15
Compare
@jrosen48 Yes, I have updated this PR. |
8b68b15
to
b8200b5
Compare
eeac039
to
485f4f4
Compare
485f4f4
to
7cffbe3
Compare
7cffbe3
to
2e6228d
Compare
…ense, but I only have four pages on this example site in total, and I want to show them in four pages)
2e6228d
to
87f7e2d
Compare
Normally when you list posts, you use something like
range .Data.Pages
, which will show all posts in a single list. Sometimes when you have a large number of posts, you may want to show, for example, 10 posts per page, and provide a navigation menu so that readers can go to the next/previous 10 posts. In this case, you can apply.Paginate
to.Data.Pages
, e.g.range (.Paginate .Data.Pages)
, and Hugo will automatically retrieve a subset of posts for you to list.Hugo has provided an internal pagination template to build the navigation menu that consists of page numbers:
Lastly, you may need to tweak the CSS to display the navigation menu appropriately.
In this example, I set
paginate = 1
inconfig.toml
, which is an extreme case. Its default value is 10 (i.e. 10 posts per page). I only have four posts on this example website, and I just want to display them on four pages as an example.Preview:
Documentation of pagination in Hugo: https://gohugo.io/templates/pagination/