简体   繁体   English

Jekyll对类别帖子的分页

[英]Jekyll pagination for categories' posts

I have implemented this example-site , it's not a real site, just an example, I did categories list in the right side of the site, they're actually pages, every one as one category (there was no used plugins for this). 我已经实现了这个示例站点 ,它不是一个真实的站点,只是一个例子,我在站点的右侧做了类别列表,它们实际上是页面,每个都作为一个类别(没有用过的插件) 。

they don't query posts with standart method, like bellow 他们不会使用标准方法查询帖子,如贝娄

{% for post in site.categories %}
   {{the post}}
{ endfor }

BUT like this in every page (category) I loop so 但是在每个页面(类别)中这样都是这样的

{% for post in site.posts %}


{% assign cat = page.title %}

{% assign post_cat = post.categories | join: '-' %}

{% if post_cat contains cat %}
    here goes the posts...
{% endif %}


{% endfor %}

I did so, because as written in jekyll's documentation, pagination can't work with quering posts via tags or categoires 我是这样做的,因为正如jekyll的文档中所写,分页不能通过标签或categoires查询帖子

  • Pagination does not support tags or categories Pagination pages through every post in the posts variable regardless of variables defined in the YAML Front Matter of each. 分页不支持标签或类别分页页面通过posts变量中的每个帖子,而不管每个帖子中YAML Front Matter中定义的变量。 It does not currently allow paging over groups of posts linked by a common tag or category. 它目前不允许对通过公共标记或类别链接的帖子组进行分页。 * *

source 资源

I thought if every category (in this case every page - index.html) has its own index.html, Ican paginate categories, but unfortunately I can't. 我想如果每个类别(在这种情况下每个页面 - index.html)都有自己的index.html,Ican分页类别,但不幸的是我不能。

In home page paginations works as you can see 在主页中,您可以看到分页

here is the site 这是网站

here is the site's source 这是该网站的来源

I don't want use plugin for this, because all things like "related posts via tags", "every post categories linked to its categories page", and the other things I did without plugins, and so can write posts directly from github. 我不想使用插件,因为所有的事情,如“通过标签的相关帖子”,“链接到其类别页面的每个帖子类别”,以及我没有插件的其他事情,所以可以直接从github写帖子。

How can I do pagination for the categories' posts ? 如何对类别的帖子进行分页?

In source there are in the folder categories and here - every category in its folder 在源代码中,文件夹类别和此处 - 文件夹中的每个类别都有

Currently, you can't. 目前,你不能。

You need to create a plugin for that if you want it to work. 如果你想让它工作,你需要为它创建一个插件。 I've built quite a lot of templates using pure jekyll (without plugins), and this is one of the limitations that you can not get around. 我使用纯jekyll(没有插件)构建了很多模板,这是你无法解决的限制之一。

Thank you very much for the limitation clue. 非常感谢你的限制线索。

As as a workaround to the plugin I created a specific layout listing pages for a category. 作为插件的变通方法,我创建了一个列出类别页面的特定布局。 Applying the layout to static pages created for important categories is slight pain to avoid writing a plugin. 将布局应用于为重要类别创建的静态页面是避免编写插件的轻微痛苦。 Finally I just had to create links between post categories and page using a category layout. 最后,我只需要使用类别布局在帖子类别和页面之间创建链接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM