查询鹈鹕主题中的特定文章(通过标签/类别) [英] Querying for specific articles (via tag/category) in Pelican themes
本文介绍了查询鹈鹕主题中的特定文章(通过标签/类别)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以通过Pelican模板文件中的Jinja设置查询参数?
Is it possible to set query parameters via jinja in Pelican template files?
index.html
{% if articles %}
{% for article in articles_page.object_list if article.category == 'article' %}
#stuff
{% endfor %}
{% endif %}
这将返回文章类别中的文章,但前提是它们恰好在已查询的文章中.理想的设置是抓取y类(或带有y标签)的x篇文章-可以吗?
This will return articles in the article category, but only if they happen to be in the articles already queried for. The desirable setup would be to grab x articles in y category (or with y tag) - is that possible?
推荐答案
此代码段适用于我,以带回所有与标签匹配的文章的列表:
This code snippet works for me to bring back a list of all articles matching a tag:
{% block content %}
<ul>
{% for article in articles if FAVORITES_TAG in article.tags %}
{% if loop.index <= FAVORITES_COUNT %}
<li><a href="{{ SITEURL }}/{{ article.url }}">{{ article.title }}</a></li>
{% endif %}
{% endfor %}
</ul>
{% endblock %}
我在配置中设置了FAVORITES_TAG和FAVORITES_COUNT个变量.希望对您有所帮助.
I set the FAVORITES_TAG and FAVORITES_COUNT variables in the config. I hope that helps.
这篇关于查询鹈鹕主题中的特定文章(通过标签/类别)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文