向 octopress 添加 post 类型

Adding a post type to octopress

我正在开发一个供个人使用的博客,并想在其中添加新闻功能。 此功能将显示我放在 _news 文件夹中的五个最近的新闻降价文件。但我无法理解如何使用模板中的液体标记访问目录,就像访问 _posts 文件夹中的帖子一样。

创建 posts 新闻类型的唯一方法是使用插件。

但我认为您的问题可以通过更简单的方式解决,使用 categories or tags

在这里我会解释标签的使用,但它与类别相同。

带有 news 标签的 post :

---
layout: post
title:  "Post 2"
date:   2015-08-12 18:02:44
tags:
  - news
  - javascript
  - anything else
---
Post 2 content

用于获取所有标记为 posts 的新闻的循环:

  <ul>
    {% for post in site.posts %}
    {% if post.tags contains "news" %}
      <li>
        <h2>
          <a href="{{ post.url | prepend: site.baseurl }}">{{ post.title }}</a>
        </h2>
      </li>
    {% endif %}
    {% endfor %}
  </ul>

尝试使用 collections 而不是帖子。对于 news 集合,集合可以通过 Jekyll/Liquid 使用 {% for n in site.news %} 进行迭代。