Jekyll pagination on multiple pages

2019-02-28 03:01发布

I am new to html/css but am attempting to create a blog using Jekyll and this theme I found here https://github.com/rosario/kasper

The homepage index.html has the all the posts in a paginated list. This is cool. However i would like to group my posts into different categories and have an additional page for each group which would have a paginated list of just posts of that groups.

I can create the additional pages but can't get the lists using any sort of variant of the code in index.html but specifying a group.

Is this possible?

2条回答
小情绪 Triste *
2楼-- · 2019-02-28 03:25

There is also another way to do that. Is using Jekyll Collections.

For each collection you can have a _folder containing your markdown files. Then you can call your posts within this folder from whatever page you want.

To do so, you will need to: 1st. add your collections to your _config.yml file:

collections:
  example1:
    permalink: /example1/:path/
  example2:
    permalink: /example2/:path/
  example3:
    permalink: /example3/:path/

2nd. create a folder to each collection, like: _example1, _example2 and _example3

3rd. create a new html file from which you call each collection:

{% for article in site.example1 %} ... {% endfor %}

That's it! I hope to have helped. If I have, please mark this answer as useful. If you need more assistance, feel free to contact me.

查看更多
闹够了就滚
3楼-- · 2019-02-28 03:36

You should share your code with your answer if you want a more detailed answer for your question. As far as I understood you are having trouble with creating a list of blog posts that are all same category. If this is correct then you can achieve it by using liquid for loop. If you look into the code on your index.html it has this for loop

{% for post in paginator.posts %}

If you modify it like below

{% for post in site.categories.comedy %}

Where comedy is a category name. This way we access the category within the site object and get all the posts under this category. If you place similar loops on your separate pages while changing the category names you can have different category lists on different pages. Make sure that you correctly input the category names in your post's front matter. If I succeeded in answering your question please mark the answer as correct.

查看更多
登录 后发表回答