【问题标题】:Is it possible to style posts in octopress according to its tags?是否可以根据标签在 octopress 中设置帖子样式?
【发布时间】:2013-07-25 15:20:56
【问题描述】:

我需要为 Octopress 中所有带有“旧”标签的帖子设置不同的样式。就像,在档案中只显示标题而不显示图像,并将它们分开!我怎样才能做到这一点? (注:有近 1,500 个帖子使用旧标签)

【问题讨论】:

    标签: css jekyll octopress


    【解决方案1】:

    您可以简单地将标签用作 css 类:

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

    这样您就可以通过 css 为任何标签轻松设置链接样式。

    【讨论】:

      【解决方案2】:

      我假设您有一个 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 以及 Liquid 的 if-elseforcontains 能够完成与专门标记帖子样式相关的大部分任务。

      【讨论】:

      • 有一个小问题。代码不起作用。它将带有 old 标签的帖子带到正常的帖子列表中。它不识别旧标签。我认为这是因为一篇文章有​​多个标签。如何解决这个问题?如何在 post.tags 中搜索子字符串“旧”?
      • 已修复!用“旧”代替旧!
      • 太好了 :) 抱歉,我正在上班的路上,所以没有办法测试代码。顺便说一句,如果我的回答对您有帮助,您可以将其指定为最佳答案吗?谢谢!
      猜你喜欢
      • 2011-05-06
      • 2010-12-26
      • 2022-06-11
      • 1970-01-01
      • 2016-10-17
      相关资源
      最近更新 更多