Skip to content

Instantly share code, notes, and snippets.

@intfrr
Forked from nimbupani/index.html
Last active April 20, 2017 19:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save intfrr/0c3956ceb4e2e59cdd21 to your computer and use it in GitHub Desktop.
Save intfrr/0c3956ceb4e2e59cdd21 to your computer and use it in GitHub Desktop.
Pagination on all posts and showing latest post on home page with Jekyll
---
layout: default
title: Kriss Rott
tagline:
---
{% include JB/setup %}
<div class="blog-index">
{% assign post = site.posts.first %}
{% assign content = post.content %}
</div>
<!--
This loops through the paginated posts
And renders the post
-->
{% assign i = 0 %}
{% for post in paginator.posts %}
{% if i == 0 %}
<h1><a href="{{ post.url }}">{{ post.title }}</a></h1>
<p class="author">
<span class="date">{{ post.date | date: '%B %d, %Y' }}</span>
</p>
<div class="content">
{{ post.content }}
</div>
{% endif %}
{% assign i = i | plus: 1 %}
{% endfor %}
<hr/>
<!--
This loops through the paginated posts
And get the actual post's index
-->
{% assign next_post_index = 1 %}
{% for page in (1..paginator.total_pages) %}
{% if page == paginator.page %}
{% break %}
{% endif %}
{% assign next_post_index = next_post_index | plus: 1 %}
{% endfor %}
<!--
This loops through the paginated posts
And renders the next post
-->
{% assign next_post_index = next_post_index | plus: 1 %}
<!--<h1>{{next_post_index}}</h1>-->
{% assign i = 1 %}
{% for post in site.posts %}
{% if i == next_post_index%}
{% if post.hidden != true %}
<article class="home" style="margin-top:40px">
<span class="post-date">
{% assign d = post.date | date: "%d" | plus:'0' %}
{{ post.date | date: "%B" }}
{% case d %}
{% when 1 or 21 or 31 %}{{ d }}st,
{% when 2 or 22 %}{{ d }}nd,
{% when 3 or 23 %}{{ d }}rd,
{% else %}{{ d }}th,
{% endcase %}
{{ post.date | date: "%Y" }}
</span>
<h3>
<a href="{{ BASE_PATH }}{{ post.url }}">{{ post.title }}</a>
</h3>
<div>
{% if post.fullview %}
{{ post.content }}
{% else %}
<a href="{{ BASE_PATH }}{{post.url }}">
{% if post.shortinfo %}
{{ post.shortinfo }}
{% elsif post.description %}
{{ post.description }}
{% else %}
{{ post.excerpt }}
{% endif %}
</a>
{% endif %}
</div>
</article>
{% endif %}
{% endif %}
{% assign i = i | plus: 1 %}
{% endfor %}
<hr/>
<!--
This loops through the paginated posts
And renders the pager
-->
<ul class="pager">
{% if paginator.previous_page %}
<li class="previous">
{% if paginator.previous_page == 1 %}
<a href="{{ BASE_PATH }}/">&larr; Newer</a>
{% else %}
<a href="{{ BASE_PATH }}/{{ site.paginate_path | replace: ':num', paginator.previous_page }}">&larr; Newer</a>
{% endif %}
</li>
{% else %}
<li class="previous disabled">
<a>&larr; Newer</a>
</li>
{% endif %}
<li>
<span class="page_number">Page: {{ paginator.page }} of {{ paginator.total_pages }}</span>
</li>
{% if paginator.next_page %}
<li class="next">
<a href="{{ BASE_PATH }}/{{ site.paginate_path|replace: ':num',paginator.next_page }}">Older &rarr;</a>
</li>
{% else %}
<li class="next disabled">
<a>Older &rarr;</a>
</li>
{% endif %}
</ul>
...
paginate: 1
paginate_path: "posts/page:num/"
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment