使用 Lektor,尝试确定如何在主登陆(根)页面上按发布日期列出最近的三个博客。我觉得我应该使用宏,但我不明白如何将博客传递到页面模板,或者这是否是流程 block 的示例?我已在 page.ini 中添加了如下所示的部分:
[children]
model = blog-post
order_by = -pub_date, title
但似乎无法在模板中循环它们(没有抛出错误但不迭代)。完全迷失了,但仍在消耗文档。
最佳答案
我最终使用了 site.query直接在布局模板中提供类功能(基于博客快速入门)。
{% for blogpost in site.query('/blog').order_by('pub_date').limit(3) %}
<div class="post col-md-4">
<div class="post-details">
<div class="post-meta d-flex justify-content-between">
<div class="date">{{ blogpost.pub_date }}</div>
</div><a href="post.html"> <!-- fix this one shortly -->
<h3 class="h4">{{ blogpost.title }}</h3></a>
<p class="text-muted">{{ blogpost.teaser }}</p>
</div>
</div>
{% endfor %}
关于lektor - 在主页上显示最近的博客事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51092740/