2015-09-04 44 views
1

如何为邮政类别设置不同的布局?例如,如果我有“玩具”和“剑”作为我的帖子的类别,我希望页面列表“玩具”具有与页面列表“剑”不同的布局。如果帖子处于没有自己的布局的类别中,更好的办法是使用默认的“产品”布局。有关如何使用jekyll实现这一点的任何想法?如何为每个类别设置不同的布局?

+0

你想自定义布局的页面列出一个特定类别的所有帖子? – approxiblue

回答

1

由于您的文档的语义不会在类别之间改变,我认为您必须用CSS来解决这个问题。

sword_list.html

--- 
category: sword 
layout: product_listing 
title: swords list 
--- 
{% include product_listing_loop %} 

_includes/product_listing_loop.html

<div class="{{page.category}}"> 
<ul> 
{% for post in categories[page.category] %} 
    <li>{{ post.title }}</li> 
{% endfor %} 
</ul> 
</div> 

你甚至可以使用page.category在主模板的body元素的类。

编辑:如果你真的需要有不同的标记,你可以尝试:

sword_list.html

--- 
category: sword 
layout: product_listing 
title: swords list 
--- 
{% assign include_name = 'category_' | append: {{page.category}} %} 
{% include {{include_name}} %} 

这将调用_includes/category_sword.html

+0

听起来不错,(类别[page.category]很好!)但是如果我需要为每个类别使用不同的标记呢? –

+0

编辑我的答案 –

相关问题