2013-07-25 47 views

回答

0

我假设你有一个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.postspost.tagssite.tags.TAGNAME,有液体的if-else在一起, forcontains能够完成与特定标记帖子的样式相关的大部分任务。

+0

有一个小问题。该代码不起作用。它将带有标签的帖子带到正常的帖子列表中。它不识别旧标签。我认为它是因为一个帖子有多个标签。如何解决这个问题?如何在post.tags中搜索子字符串'old'? – THpubs

+0

固定!使用'旧'而不是旧的! – THpubs

+0

太棒了:)对不起,我正在上班的路上,所以没有办法测试代码。顺便说一句,如果我的回答对你有帮助,你可以将它作为最佳答案吗?谢谢! – agarie

0

你可以简单地使用标记为CSS类:

<ul> 
    {% for post in site.posts %}  
     <li><a href="{{ post.url }}" class="tags {{ post.tags | join:' ' }}">{{ post.title }}</a></li>  
    {% endfor %} 
</ul> 

这样,你可以样式任何标签通过CSS轻松链接。

相关问题