Pagination within a multiblog environment for a specific blog

How do I use the middleman blog pagination for a specific blog in a multiblog middleman setup?

Currently I use:

blog(category).articles[page_start .. page_end].each_with_index do |current_article,i|

To loop thru specific articles, with category a variable thru proxy in config.rb. I found out that the pagination locals use a different context than above loop and loop over the first blog in config.rb likepage_articles do.

Thx.

Use the frontmatter section to tell Middleman which blog you want to generate a paginated listing for. e.g.:

---
title: Episodes
pageable: true
blog: episodes
per_page: 10
---

Then you should be able to use the page_articles method in your template, as well as other pagination helpers. e.g.:

<% page_articles.each_with_index do |episode, i| %>
  <h2><%= link_to episode.title, episode %></h2>
<% end %>

<% if paginate %>
  <% if prev_page %>
    <p><%= link_to 'Prev page', prev_page %></p>
  <% end %>
  <% if next_page %>
    <p><%= link_to 'Next page', next_page %></p>
  <% end %>
<% end %>

Finally, make sure that your blog is set to paginate in the config.rb file, e.g.:

activate :blog do |blog|
  blog.name = "episodes"
  blog.paginate = true
end

I hope that helps!

1 Like

Works like a charm. Thx! I didn’t know of the blog frontmatter.