【发布时间】:2013-07-25 15:20:56
【问题描述】:
我需要为 Octopress 中所有带有“旧”标签的帖子设置不同的样式。就像,在档案中只显示标题而不显示图像,并将它们分开!我怎样才能做到这一点? (注:有近 1,500 个帖子使用旧标签)
【问题讨论】:
我需要为 Octopress 中所有带有“旧”标签的帖子设置不同的样式。就像,在档案中只显示标题而不显示图像,并将它们分开!我怎样才能做到这一点? (注:有近 1,500 个帖子使用旧标签)
【问题讨论】:
您可以简单地将标签用作 css 类:
<ul>
{% for post in site.posts %}
<li><a href="{{ post.url }}" class="tags {{ post.tags | join:' ' }}">{{ post.title }}</a></li>
{% endfor %}
</ul>
这样您就可以通过 css 为任何标签轻松设置链接样式。
【讨论】:
我假设您有一个 old 类来区分帖子,或者您可以使用 old_posts 类设置旧帖子列表的样式。您可以创建两个单独的列表:
<ul class="old_posts">
{% for post in site.tags.old %}
<li><a href="{{ post.url }}">{{ post.title }}</a></li>
{% endfor %}
</ul>
<ul class="new_posts">
{% for post in site.posts %}
{% unless post.tags contains 'old' %}
<li><a href="{{ post.url }}">{{ post.title }}</a></li>
{% endif %}
{% endfor %}
</ul>
或者您可以创建一个列表,其中旧帖子接收特殊类别old:
<ul>
{% for post in site.posts %}
{% if post.tags contains 'old' %}
<li><a href="{{ post.url }}" class="old">{{ post.title }}</a></li>
{% else %}
<li><a href="{{ post.url }}" class="new">{{ post.title }}</a></li>
{% endif %}
{% endfor %}
</ul>
基本上,site.posts、post.tags 和 site.tags.TAGNAME 以及 Liquid 的 if-else、for 和 contains 能够完成与专门标记帖子样式相关的大部分任务。
【讨论】: