我想做的是在索引页上为目录页的子类别创建快捷方式。 在目录页面上,我有这个用于浏览集合的代码:
<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>
这段代码的作用是显示快捷方式,但我只能选择“全部”。下拉列表不显示任何其他子类别。有什么建议么?谢谢!
最佳答案
在索引页上,未设置 collection
变量。您需要使用以下内容自己分配它:
{% assign collection = collections.all %}
(在你已有的代码之上)
collections.all
是一个 Automatic Collection .
关于php - Shopify - 如何在 index.liquid 上显示 "Browse by subcategories"表单?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15366000/