【问题标题】:How do I display a specific post in Jekyll?如何在 Jekyll 中显示特定帖子?
【发布时间】:2015-12-15 17:44:26
【问题描述】:

我想将Jekyll 本质上用作CMS,所以我想从帖子中获取内容并将其显示在我网站的特定区域。

{% for post in site.posts %}
    {{ post.content }}
 {% endfor %}

这会显示所有帖子中的所有内容,但是我想一次从一个帖子中获取内容。我对 Jekyll 还很陌生,所以我不确定我是否应该在我的帖子中添加 YAML 前面的内容,并使用“用于带有title_____" post.content 的站点中的帖子”来定位它们。

谢谢!!

【问题讨论】:

    标签: github content-management-system yaml jekyll


    【解决方案1】:

    {% assign thepost = site.posts | where:"slug","post_slug" %}
    {% for post in thepost %}
     {{ post.content }}
    {% endfor %}

    在帖子上;

    slug: post_slug

    【讨论】:

    • 谢谢。您也可以使用title。它有效。
    【解决方案2】:

    我想通了,抱歉我过早发布了。

    答案是使用 YAML 前题为您的帖子添加一个类别,然后在您的包含文件中使用:

    {% for post in site.categories.CATEGORYNAMEHERE %}
        {{ post.content }}
    {% endfor %}
    

    【讨论】:

    • 如果您只想显示一个帖子,这将不起作用。
    猜你喜欢
    • 2021-12-29
    • 2018-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-27
    • 2014-01-19
    • 1970-01-01
    相关资源
    最近更新 更多