以下是该场景:我有一个在Siteleaf上运行的投资组合网站(siteleaf.com - 使用流动模板),我有一个投资组合部分,其中有几个项目作为帖子。诀窍是我只希望带有标签精选
的项目我能够发布帖子,但只限制显示的帖子数量,但不限制分配的标签。以下是我使用的代码:
<ul class="container work-gallery clearfix">
{% for post in site.pages['work'].posts limit:6 %}
<li class="col-md-6 thumb">
<a href="{{post.url}}" style="background-image: url('{{post.assets.first.url}}');">
<h4>{{post.title}}</h4>
</a>
</li>
{% endfor %}
</ul>
有办法吗?谢谢你的帮助!
答案 0 :(得分:1)
我打赌你已经把它想出来了,因为你已经非常接近了。
有几种方法可以执行此操作(更多信息here和here)。对于此示例,我假设您使用了Siteleaf的默认tags
分类法(也就是标记集)。
<ul>
{% for post in taxonomy['tags']['featured'].posts limit:6 %}
<li>
<a href="{{post.url}}">
<h4>{{post.title}}</h4>
</a>
</li>
{% endfor %}
</ul>
如果您想与其他人合作,可以添加if
。
或者,如果您想真正参加派对,可以使用assign
标记来存储变量,然后将其用作输出条件(或其他tags
或变量)。
{% assign featured_posts = '' %}
<ul>
{% for post in taxonomy['tags']['featured'].posts limit:6 %}
{% assign featured_posts = featured_posts | append:',' | append:post.id %}
<li>
<a href="{{post.url}}">
<h4>{{post.title}}</h4>
</a>
</li>
{% endfor %}
...
<ul>
{% for post in posts %}
{% unless featured_posts contains post.id %}
<li class="not-featured">
<a href="{{post.url}}">
<h4>{{post.title}}</h4>
</a>
</li>
{% endunless %}
{% endfor %}
</ul>