Querying for specific articles (via tag/category) in Pelican themes

痞子三分冷 提交于 2019-12-05 13:03:28

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 %}

I set the FAVORITES_TAG and FAVORITES_COUNT variables in the config. I hope that helps.

I ran into the same problem, and found a solution

{% if articles %}
    {% for article in articles_page.object_list if article.category.name == 'article' %}        
        #stuff
    {% endfor %}
{% endif %}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!