Skip to content

Commit 88b534d

Browse files
committed
Adding pagination in blog posts list
1 parent 6a6482d commit 88b534d

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

_config.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,18 @@ email: myemail@gmail.com
1818

1919
exclude: [README.md, Gemfile, Gemfile.lock, node_modules, gulpfile.js, package.json, _site, src, vendor]
2020

21+
#pagination
22+
paginate: 5
23+
paginate_path: "blog/page:num/"
24+
2125
gems:
2226
- jemoji
2327
- jekyll-mentions
2428
- jekyll-seo-tag
2529
- jekyll-feed
2630
- jekyll-sitemap
2731
- jekyll-gist
32+
- jekyll-paginate
2833

2934
jekyll-mentions:
3035
base_url: https://github.com

_includes/pagination.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<div class="pagination">
2+
{% if paginator.previous_page %}
3+
<a href="{{ paginator.previous_page_path }}" class="previous">Previous</a>
4+
{% else %}
5+
<span class="previous">Previous</span>
6+
{% endif %}
7+
<span class="page_number ">Page: {{ paginator.page }} of {{ paginator.total_pages }}</span>
8+
{% if paginator.next_page %}
9+
<a href="{{ paginator.next_page_path }}" class="next">Next</a>
10+
{% else %}
11+
<span class="next ">Next</span>
12+
{% endif %}
13+
</div>
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
---
22
layout: default
3-
permalink: /blog/index.html
43
title: Blog
54
---
65
{% include header.html %}
76

87
<section class="home__sections">
9-
{% for post in site.posts %}
8+
{% for post in paginator.posts %}
109
<div class="home__sections-single {% if post.star == true %}star{% endif %}">
1110
<a href="{{ site.url }}{{ post.url }}">
1211
<aside><time datetime="{{ post.date | date:"%d-%m-%Y" }}">{{ post.date | date: "%b %d %Y" }}</time></aside>
1312
<h3>{{ post.title }}</h3>
1413
</a>
1514
</div>
16-
{% endfor %}
15+
{% endfor %}
16+
{% include pagination.html%}
1717
</section>
1818

19-
{% include footer.html %}
19+
{% include footer.html %}

blog/index.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
layout: blog
3+
title: Blog
4+
---
5+
##Blog

0 commit comments

Comments
 (0)