jekyll - 在 Jekyll 博客中显示当前类别的帖子
问题描述
我想在 Jekyll 博客中显示当前类别的帖子。所以,我写了如下代码。
<div class="side-left col-sm-4 col-md-4">
{% for category in site.categories %}
{% if page.categories == category.first %}
<h3 class="lead"> {{ category | first }} </h3><hr>
<ul>
{% for post in category[1] limits:5 %}
<li><a href="{{ post.url }}" style="color:whitesmoke;"> {{ post.title | truncate:40 }}</a></li>
{% endfor %}
</ul>
{% endif %}
{% endfor %}
</div>
但是当我更新博客时,侧边栏上什么也没有发生。为了检查,我在第 2 行和第 3 行之间写了 {{ page.categories }} {{ category.first }}。侧边栏显示了我
阿巴卡德
什么是问题,我该如何解决?
解决方案
{{ category }} 是一个字符串而不是一个数组,所以当你写 {{ category.first }} 时,你会得到字符串的第一个字母;)。
推荐阅读
- php - 我没有收到来自服务器的信息
- javascript - 在输入框html中显示月份名称
- php - 虽然我设置了时区配置,但 Carbon::now() 时区在 Laravel 6 上永远不会改变
- ios - 在 Xcode 11 中开始 iOS 应用程序开发时在用户界面上选择哪个选项?Swift UI 还是 Storyboard?
- ios - iOS:架构 x86_64 clang 的 221 个重复符号:错误:链接器命令失败,退出代码为 1
- sql - SQL Server 监视旧应用程序中的数据插入、更新和删除
- c# - 当我执行“构建>清洁解决方案”时,我想将所有“.proto”文件从一个目录复制到另一个目录]
- ruby - 如何对其中包含值的哈希进行排序
- google-colaboratory - 尝试连接到 Google Colab 上的托管运行时
- rust - 如何使用相同的可变借用两次调用 serde_json::to_writer?