精选 collection 中的 Shopify 'view collection' 按钮
Shopify 'view collection' button in featured collection
我正在为网上商店设置基本内容的主题,并尝试向主页上的特色 collection 添加一个 'view collection' 按钮。在文档中,它指出通常我只需要执行 collection.url 并获得 url。但这似乎不起作用。有人可以说我做错了什么吗?
(https://help.shopify.com/themes/liquid/objects/collection#collection-url)
{% if section.settings.show_view_all %}
<hr class="hr--clear">
<div class="text-center">
<a href="{{ section.settings.featured_collection.url }}" class="btn">
{{ 'collections.general.view_all' | t }}
</a>
</div>
{% endif %}
</div>
{% schema %}
{
"name": "Featured collection",
"class": "index-section",
"settings": [
{
"type": "text",
"id": "title",
"label": "Heading",
"default": "Featured collection"
},
{
"type": "collection",
"id": "featured_collection",
"label": "Collection"
},
您应该检查 collection 设置类型:
https://help.shopify.com/themes/development/theme-editor/settings-schema#collection:
The output of the option the merchant selects from the drop-down is the handle of the collection.
所以,而不是:
{{ section.settings.featured_collection.url }}
你应该使用:
{{ collections[section.settings.featured_collection].url }}
我这样包装了 h2 标签:
{% if section.settings.title != blank %}
<a href="/collections/{{ section.settings.home_page_featured_products }}"><h2 class="small--text-center">{{ section.settings.title | escape }}</h2></a>
{% endif %}
因为我从来不打算让 collection slug 有所不同,所以这对我有用。你的旅费可能会改变。这是使用 'Simple' 主题。
我正在为网上商店设置基本内容的主题,并尝试向主页上的特色 collection 添加一个 'view collection' 按钮。在文档中,它指出通常我只需要执行 collection.url 并获得 url。但这似乎不起作用。有人可以说我做错了什么吗? (https://help.shopify.com/themes/liquid/objects/collection#collection-url)
{% if section.settings.show_view_all %}
<hr class="hr--clear">
<div class="text-center">
<a href="{{ section.settings.featured_collection.url }}" class="btn">
{{ 'collections.general.view_all' | t }}
</a>
</div>
{% endif %}
</div>
{% schema %}
{
"name": "Featured collection",
"class": "index-section",
"settings": [
{
"type": "text",
"id": "title",
"label": "Heading",
"default": "Featured collection"
},
{
"type": "collection",
"id": "featured_collection",
"label": "Collection"
},
您应该检查 collection 设置类型: https://help.shopify.com/themes/development/theme-editor/settings-schema#collection:
The output of the option the merchant selects from the drop-down is the handle of the collection.
所以,而不是:
{{ section.settings.featured_collection.url }}
你应该使用:
{{ collections[section.settings.featured_collection].url }}
我这样包装了 h2 标签:
{% if section.settings.title != blank %}
<a href="/collections/{{ section.settings.home_page_featured_products }}"><h2 class="small--text-center">{{ section.settings.title | escape }}</h2></a>
{% endif %}
因为我从来不打算让 collection slug 有所不同,所以这对我有用。你的旅费可能会改变。这是使用 'Simple' 主题。