使用螺栓,我想抓住我的4个最新条目。很简单。但是,我需要第一个和第三个条目在他们周围有一个特定的CSS类,而第二个和第四个条目将有他们自己的类。奇/偶记录具有独特的CSS类
最终的HTML应该是这个样子:
<div class="quarter alt">
<h3><a href="{{ record.link }}">{{ record.title }}</a></h3>
<p>{{ record.teaser }}</p>
<p><a href="{{ record.link }}">Read more</a>.</p>
</div>
<div class="quarter">
<h3><a href="{{ record.link }}">{{ record.title }}</a></h3>
<p>{{ record.teaser }}</p>
<p><a href="{{ record.link }}">Read more</a>.</p>
</div>
<div class="quarter alt">
<h3><a href="{{ record.link }}">{{ record.title }}</a></h3>
<p>{{ record.teaser }}</p>
<p><a href="{{ record.link }}">Read more</a>.</p>
</div>
<div class="quarter">
<h3><a href="{{ record.link }}">{{ record.title }}</a></h3>
<p>{{ record.teaser }}</p>
<p><a href="{{ record.link }}">Read more</a>.</p>
</div>
我与片段和文档玩耍了和我在那里我找到了点loop.first但当然,仅适用于第一个条目:
{% setcontent records = "entries/latest/4" %}
{% for record in records %}
{% if loop.first %}
<div class="quarter alt">
<h3><a href="{{ record.link }}">{{ record.title }}</a></h3>
<p>{{ record.teaser }}</p>
<p><a href="{{ record.link }}">Read more</a>.</p>
</div>
{% else %}
<div class="quarter">
<h3><a href="{{ record.link }}">{{ record.title }}</a></h3>
<p>{{ record.teaser }}</p>
<p><a href="{{ record.link }}">Read more</a>.</p>
</div>
{% endif %}
{% endfor %}
任何想法如何编辑我的模板来完成我后?非常感谢。
啊,当然是。谢谢。 – user5710 2014-10-17 00:07:24