Paul Schraven
Paul Schraven

Reputation: 1

Middleman Blog Pagination shows all articles

I have been trying to activate Pagination for my Middleman Blog, but for some reason, even though pagination itself seems to work (as signified by the buttons at the bottom, leading me until page three), all articles are shown on each individual page, instead of just ten

section in config.rb

activate :blog do |blog|
  blog.name = "en"
  blog.prefix = "blog"
  blog.permalink = "/{year}/{month}/{day}/{title}.html"
  blog.sources = "/posts/:year-:month-:day-:title.html"
  blog.layout = "blog_layout"
  blog.tag_template = "tag.html"
  blog.paginate = true
  blog.page_link = "page:num"
  blog.per_page = 10
end

Blog Index.html

---
pageable: true  
blog: en
priority: 1.0
change_frequency: weekly
description: Tbd.
title: Blog
---
<div class="page-content">
  <div class="container">
    <ul class="blog-post-list">
        <% blog.articles.each do |article| %>
        <li>
          <a href="<%= article.url %>">
            <div>
              <img src="<%= article.data.image %>" class="blog-post-list__image" />
            </div>
            <div class="blog-post-list__post-preview">
              <p class="blog-post-list__title"><%= article.title %></p>
              <p><%= article.summary(140, '...') %></p>
              <span><%= article.date.strftime('%B %e, %Y') %></span>
            </div>
          </a>
        </li>
      <% end %>
      <ul class="paginate">
        <% if paginate && num_pages > 1 %>
            <% if prev_page %>
                <p class="previous"><%= link_to 'Previous page', prev_page %></p>
            <% end %>
        <% end %>
        <% if paginate %>
            <% if next_page %>
                <p class="next "><%= link_to 'Next page', next_page %></p>
            <% end %>
        <% end %>
    </ul>
  </ul>
  </div>
</div>

Any hints what could be the issue here, that causes all articles to be displayed anyways would be highly appreciated! Thanks in advance :)

Upvotes: 0

Views: 278

Answers (1)

nicodo
nicodo

Reputation: 47

Is that not because you use blog.articles.each and should use page_articles instead? I think you have to change blog.articles.each (the total number of articles) and use something like <% page_articles.each do |article| %> to get the number of articles you want on your page.

Upvotes: 1

Related Questions