我要做的是在目录页面的子类别的索引页面上创建一个快捷方式。 在目录页面上,我有用于浏览集合的代码:
<form action="" class="navigation">
<div class="category-selector-wrapper">
<label>Browse by collection:</label>
<div class="category">
<select class="navigationSelector">
<option value="/collections/all">All</option>
{% for col in collections %}
<option value="{{ col.url }}"{% if collection.handle == col.handle %}selected="selected"{% endif %}>{{ col.title }}</option>
{% endfor %}
</select>
</div>
</div>
{% assign colItems = collection.all_tags | size %}
{% if colItems > 0 %}
<div class="category-selector-wrapper">
<label>Subcategory:</label>
<div class="category">
<select class="navigationSelector">
{% if collection.handle %}
<option value="/collections/{{ collection.handle }}">All</option>
{% elsif collection.products.first.type == collection.title %}
<option value="{{ collection.title | url_for_type }}">All</option>
{% elsif collection.products.first.vendor == collection.title %}
<option value="{{ collection.title | url_for_vendor }}">All</option>
{% endif %}
{% for tag in collection.all_tags %}
{% if current_tags contains tag %}
<option value="/collections/{{ collection.handle }}/{{ tag | handleize }}" selected="selected">{{ tag }}</option>
{% else %}
<option value="/collections/{{ collection.handle }}/{{ tag | handleize }}">{{ tag }}</option>
{% endif %}
{% endfor %}
</select>
</div>
</div>
{% endif %}
<label class="total">{{ collection.products_count }} {{ collection.products_count | pluralize: 'item', 'items' }} total</label>
</form>
我试过的是在index.liquid中输入以下代码:
<form action="" class="navigation">
<div class="category-selector-wrapper">
<label>Subcategory:</label>
<div class="category">
<select class="navigationSelector">
{% if collection.handle %}
<option value="/collections/{{ collection.handle }}">All</option>
{% elsif collection.products.first.type == collection.title %}
<option value="{{ collection.title | url_for_type }}">All</option>
{% elsif collection.products.first.vendor == collection.title %}
<option value="{{ collection.title | url_for_vendor }}">All</option>
{% endif %}
<option value="/collections/{{ collection.handle }}/{{ tag | handleize }}" selected="selected">{{ tag }}</option>
<option value="/collections/{{ collection.handle }}/{{ tag | handleize }}">{{ tag }}</option>
</select>
</div>
</div>
</form>
此代码的作用是显示快捷方式,但我只能选择“全部”。下拉列表不显示任何其他子类别。有什么建议?谢谢!
答案 0 :(得分:0)
在索引页面上未设置collection
变量。您需要使用以下内容自行分配:
{% assign collection = collections.all %}
(在您已有的代码之上)
collections.all
是Automatic Collection。