Skip to content
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 about pagination #18

Closed
kapuastop opened this issue Jul 10, 2018 · 4 comments
Closed

How about pagination #18

kapuastop opened this issue Jul 10, 2018 · 4 comments

Comments

@kapuastop
Copy link

How to set up pagination on this theme with Hugo

@htr3n
Copy link
Owner

htr3n commented Jul 10, 2018

Hi,
I assume you are asking about pagination for listing of posts in the home page. It can be easily achieved with normal Hugo pagination techniques.

What you need to do is go to hyde-hyde/layouts/index.html, then look for the code that walks through the posts and prints out each post's info.

{{ range (where .Data.Pages "Type" "not in" (slice "about" "portfolio")).GroupBy "Section" -}}
...
{{ end }}

should be changed to something like this.

{{ range (.Paginate (where .Data.Pages "Type" "not in" (slice "about" "portfolio"))).Pages -}}
...
{{ end }}
{{ template "_internal/pagination.html" . }}

Hope this works as I'm traveling and have not tried in my setting yet.

Update 2018-07-12:

  • Sorry, the previous code does not work. I updated the working code.

@htr3n
Copy link
Owner

htr3n commented Jul 16, 2018

As I haven't heard from you, I will close this issue for now. Please reopen or ask further if you wish.

@htr3n htr3n closed this as completed Jul 16, 2018
@bric3
Copy link

bric3 commented Apr 6, 2020

Hi @htr3n, since version 2.0 this part has been rewrittent, as I'm new to hugo, I wonder
how to make pagination working. I've identified two template to override

  • layouts/partials/posts-list.html
    I'm not sure how to replace this template directive {{ range . }} with a .Paginate function, idea comming from this discussion. Hugo always fail to render with my tries.

  • layouts/partials/page-list/content.html
    I just looked at this file to see what the . was about it seems it is a .Data.Pages

Ive tried many different thing but this usually ends in something like execute of template failed: template: partials/posts-list.html:1:10: executing "partials/posts-list.html" at <.Paginate>: can't evaluate field Paginate in type page.Pages

Do you have any clue or tips to make pagination work for posts page?

@bric3
Copy link

bric3 commented Apr 7, 2020

Just in case I found a solution, maybe not the best, but it works :

These files needs to be copied over the root of the Hugo site with the same relative path. And modify them as needed

  • layouts/partials/page-list/content.html
--- 1/themes/hyde-hyde/layouts/partials/page-list/content.html
+++ 2/layouts/partials/page-list/content.html
@@ -1,6 +1,4 @@
 <span class="section__title">{{ .Title }}</span>
 <ul class="posts">
-    {{ with .Data.Pages }}
-        {{ partial "posts-list.html" . }}
-    {{ end }}
-</ul>
+    {{ partial "posts-list.html" . }}
+</ul>
  • layouts/partials/posts-list.html
--- 1/themes/hyde-hyde/layouts/partials/posts-list.html
+++ 2/layouts/partials/posts-list.html
@@ -1,6 +1,7 @@
-{{ range . }}
+{{ $paginator := .Paginate (where .Pages "Type" "in" "posts") }}
+{{ template "_internal/pagination.html" . }}
+<br/>
+{{ range $paginator.Pages }}
 <li>
     <a href="{{ .RelPermalink }}" {{if .Draft}}class="draft"{{end}}>{{ .Title }}</a>
       {{if not .Date.IsZero}}
       <time class="pull-right hidden-tablet">{{ .Date.Format (.Site.Params.dateformat | default "Jan 02 '06") }}</time>
@@ -8,3 +9,4 @@
   </span>
 </li>
 {{ end }}
+<br/>
+{{ template "_internal/pagination.html" . }}   

Here I’m using the Hugo internal template for pagination but one can image using a custom template. The .Paginate directive was taken from pagination doc, however the doc have a slight issue, the where query needs to be where .Pages “Type” “in” “posts” keyword.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants