Shopify link 在主页上标记
Shopify link to tag on home page
您好,我正在尝试使用 link_to_tag 将 links 添加到我网站主页上的 collections 标签中。这在 collection 页面上工作正常,但似乎在主页上不起作用,而不是提供 url collection/tag-handle 它提供 homepage/?constraint=tag-handle
知道如何实现吗?宁愿不要求人们必须为每个标签创建一个 collection 和 link
关于我如何处理这个问题的简要总结:
{% if link.type == 'collection_link' %}
{% assign collection = link.object %}
<ul class="site-nav__dropdown">
{% for tag in collection.all_tags %}
<li>
{{ tag | link_to_tag: tag }}
</li>
{% endfor %}
</ul>
{% endif %}
谢谢
我想出了一种似乎适用于 collection 页面和非 collection 页面的解决方案......但它看起来很老套。我不知道这是否有任何缺点?
<a href="{{ link.url }}/{{tag | handle}}">{{tag}}</a>
如果您有 collection 这个名字,您可以将 collection 放在商店的任何地方。
我用过这个:
{% assign collection = collections['your-collection-handle'] %}
<ul class="">
{% for tag in collection.all_tags %}
<li>
<a href="{{ tag | handleize | prepend:'/' | within: collection }}">{{ tag }}</a>
</li>
{% endfor %}
</ul>
对于带有该特定标签的所有产品的带有 url 的标签名称,您可以使用以下内容:
{% for tag in collection.tags %}
{% assign tag_url = tag | handleize | prepend: '/' | prepend: routes.all_products_collection_url %}
{{ tag | link_to: tag_url }}
{% endfor %}
如果您想在产品卡片上使用它,这也适用于产品标签。
{% for tag in product.tags %}
{% assign tag_url = tag | handleize | prepend: '/' | prepend: routes.all_products_collection_url %}
{{ tag | link_to: tag_url }}
{% endfor %}
您好,我正在尝试使用 link_to_tag 将 links 添加到我网站主页上的 collections 标签中。这在 collection 页面上工作正常,但似乎在主页上不起作用,而不是提供 url collection/tag-handle 它提供 homepage/?constraint=tag-handle
知道如何实现吗?宁愿不要求人们必须为每个标签创建一个 collection 和 link
关于我如何处理这个问题的简要总结:
{% if link.type == 'collection_link' %}
{% assign collection = link.object %}
<ul class="site-nav__dropdown">
{% for tag in collection.all_tags %}
<li>
{{ tag | link_to_tag: tag }}
</li>
{% endfor %}
</ul>
{% endif %}
谢谢
我想出了一种似乎适用于 collection 页面和非 collection 页面的解决方案......但它看起来很老套。我不知道这是否有任何缺点?
<a href="{{ link.url }}/{{tag | handle}}">{{tag}}</a>
如果您有 collection 这个名字,您可以将 collection 放在商店的任何地方。
我用过这个:
{% assign collection = collections['your-collection-handle'] %}
<ul class="">
{% for tag in collection.all_tags %}
<li>
<a href="{{ tag | handleize | prepend:'/' | within: collection }}">{{ tag }}</a>
</li>
{% endfor %}
</ul>
对于带有该特定标签的所有产品的带有 url 的标签名称,您可以使用以下内容:
{% for tag in collection.tags %}
{% assign tag_url = tag | handleize | prepend: '/' | prepend: routes.all_products_collection_url %}
{{ tag | link_to: tag_url }}
{% endfor %}
如果您想在产品卡片上使用它,这也适用于产品标签。
{% for tag in product.tags %}
{% assign tag_url = tag | handleize | prepend: '/' | prepend: routes.all_products_collection_url %}
{{ tag | link_to: tag_url }}
{% endfor %}