Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Darep
Created January 5, 2014 19:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Darep/8272582 to your computer and use it in GitHub Desktop.
Save Darep/8272582 to your computer and use it in GitHub Desktop.
Old-school numbered pagination for middleman-blog – see http://i.imgur.com/oYa0Cfj.png
<% if paginate && num_pages > 1 %>
<div class="pagination">
<% if prev_page %>
<%= link_to '<i class="icon-arrow-left"></i> Prev', prev_page, class: 'prev page-numbers' %>
<% else %>
<span class="disabled"><i class="icon-arrow-left"></i> Prev</span>
<% end %>
<% for p in 1..num_pages %>
<% if p == page_number %>
<span class="page-numbers current"><%= p %></span>
<% elsif p == 1 %>
<%= link_to p, "/blog" %>
<% else %>
<%= link_to p, "/blog/page/#{p}" %>
<% end %>
<% end %>
<% if next_page %>
<%= link_to 'Next <i class="icon-arrow-right"></i>', next_page, class: 'next page-numbers' %>
<% else %>
<span class="disabled">Next <i class="icon-arrow-right"></i></span>
<% end %>
</div>
<% end %>
@Darep
Copy link
Author

Darep commented Jan 5, 2014

Screenshot:

@Darep
Copy link
Author

Darep commented Jan 5, 2014

TODO: add support for hiding extra pages. With over 10 pages, the pagination starts to get super weird and un-usable

@ParthKolekar
Copy link

Works for fixed prefixes. So the prefix needs to be hard-coded. For example,

/blog/<%= year %>/ 
/blog/<%= year %>/page/<%= p %> 

For calender page. And;

/blog/tags/<%= tagname %> 
/blog/tags/<%= tagname %>/page/<%= p %> 

For tag pages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment