Paginate last 10

I came across @Raymond_Camden blog on the pagination issue while learning pagination in Hugo by working with this index.html for a Hugo homepage which lists all content/posts/. I would like to paginate it to the last 10.

  • I have added a pagination value in the config.toml paginate = “10”
  • I have deleted /public folder to purge stale pages.

What could I be missing because the pagination is not working? If you want to see an actual website running this, check https://ar.al/

    {{ .Content }}

    <!-- Group by year. -->
    {{ range .Site.RegularPages.GroupByDate "2006" }}
    <h2>{{ .Key }}</h2>

      <!-- Group by month. -->
      {{ range .Pages.GroupByDate "January 2006" }}
      <h3>{{ .Key }}</h3>

        <!-- Orders content according to the "date" field in front matter. -->
        {{ range .Pages.GroupByDate "02" }}
        <h4 class='postdate date'>{{ .Key }}</h4>
        <ul>
          {{ range $index, $post := .Pages }}
            <li>
              <time datetime="{{ $post.Date.Format "2006-01-02T15:04:05Z0700" }}">
                <span class='postdate day item-{{ $index }}'>{{ $post.Date.Format "Mon" }}</span>
              </time>
              <span class='postdate'>{{ $post.Date.Format "15:04" }}</span>
              <a class='posttitle' href="{{ .RelPermalink }}">{{ $post.Title }}</a>
            </li>
          {{ end }}
        </ul>
      {{ end }}
    {{ end }}
  {{ end }}


  {{ partial "footer.html" . }}
  </body>
</html>

Hi there,

The topic you posted in is 5 years old. Please do not resurrect old topics.

The code snippet you posted contains no lines that I can see that use the Pagination feature. It is not enough to set the paginate configuration, you also need to add the template logic to render the pagination.

The docs has examples: Pagination | Hugo

Thank you for the clarifications, @pointyfar.

For those who may wonder how I went around it, this is my working code:

{{ .Content }}

        <!-- Group by year. -->
    {{ range (.Paginate (.Site.RegularPages.GroupByDate "2006")).PageGroups }}
    <h2>{{ .Key }}</h2>

      <!-- Group by month. -->
      {{ range .Pages.GroupByDate "January 2006" }}
      <h3>{{ .Key }}</h3>

        <!-- Orders content according to the "date" field in front matter. -->
        {{ range .Pages.GroupByDate "02" }}
        <h4 class='postdate date'>{{ .Key }}</h4>
        <ul>
          {{ range $index, $post := .Pages }}
            <li>
              <time datetime="{{ $post.Date.Format "2006-01-02T15:04:05Z0700" }}">
                <span class='postdate day item-{{ $index }}'>{{ $post.Date.Format "Mon" }}</span>
              </time>
              <span class='postdate'>{{ $post.Date.Format "15:04" }}</span>
              <a class='posttitle' href="{{ .RelPermalink }}">{{ $post.Title }}</a>
            </li>
          {{ end }}
        </ul>
        {{ end }}
        {{ end }}
        {{ end }}

     {{ template "_internal/pagination.html" . }}

  {{ partial "footer.html" . }}
  </body>
</html>

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