如果所有 search.results 在 Shopify 主题的 search.liquid 中都没有 item.featured_image,如何显示不同的内容
How to display different content IF all of the search.results do not have item.featured_image in Shopify Theme's search.liquid
我开始与一家已经构建并运行了相当复杂的主题的公司合作。在他们的 collection 页面和搜索页面上,没有特色图片的产品不会显示。因此,当搜索所有结果都是没有特色图片的项目时,现在只有一个空白 space 产品所在的位置。
我想知道是否可以在 search.liquid
文件中检查是否所有 search.results
都缺少 item.featured_image
,如果是这样,则跳过显示结果并显示一条消息,说明没有结果。
现在代码的精简示例如下:
{% if search.performed %}
{% paginate search.results by 60 %}
{% if search.results == empty %}
<div class="row">
<h2>Sorry! No Search Results</h2>
<p>Your search for <strong>"{{ search.terms }}"</strong> didn't
return any results.</p>
</div>
{% else %}
<div class="row">
<h1>Search Results</h1>
<p>{{ search.results_count }} Products match your search.</p>
{% include 'pagination' %}
</div>
{% for item in search.results %}
{% if item.featured_image == blank %}
{% continue %}
{% endif %}
// looped code for each item with featured image.
{% endfor %}
{% endif %}
{% endpaginate %}
{% endif %}
如有任何帮助,我们将不胜感激!
----编辑----
正如 HymnZ 让我发现的那样,只需创建一个 for 循环来计算 items.featured_image == blank
并检查该计数是否匹配 search.results_count
就可以了。
替换 {% if search.results == empty %}
,确定是否显示无结果文本,使用以下代码解决问题。
{% assign items_blank = 0 %}
{% for item in search.results %}
{% if item.featured_image == blank %}
{% assign items_blank = items_blank | plus: 1 %}
{% endif %}
{% endfor %}
{% if search.results == empty or items_blank == search.results_count %}
将{% if search.results == empty %}
行替换为以下代码
{% assign items_blank = 0 %}
{% for item in search.results %}
{% if item.featured_image == blank %}
{% assign items_blank = items_blank | plus: 1 %}
{% endif %}
{% endfor %}
{% if search.results == empty or items_blank == search.results_count %}
我开始与一家已经构建并运行了相当复杂的主题的公司合作。在他们的 collection 页面和搜索页面上,没有特色图片的产品不会显示。因此,当搜索所有结果都是没有特色图片的项目时,现在只有一个空白 space 产品所在的位置。
我想知道是否可以在 search.liquid
文件中检查是否所有 search.results
都缺少 item.featured_image
,如果是这样,则跳过显示结果并显示一条消息,说明没有结果。
现在代码的精简示例如下:
{% if search.performed %}
{% paginate search.results by 60 %}
{% if search.results == empty %}
<div class="row">
<h2>Sorry! No Search Results</h2>
<p>Your search for <strong>"{{ search.terms }}"</strong> didn't
return any results.</p>
</div>
{% else %}
<div class="row">
<h1>Search Results</h1>
<p>{{ search.results_count }} Products match your search.</p>
{% include 'pagination' %}
</div>
{% for item in search.results %}
{% if item.featured_image == blank %}
{% continue %}
{% endif %}
// looped code for each item with featured image.
{% endfor %}
{% endif %}
{% endpaginate %}
{% endif %}
如有任何帮助,我们将不胜感激!
----编辑----
正如 HymnZ 让我发现的那样,只需创建一个 for 循环来计算 items.featured_image == blank
并检查该计数是否匹配 search.results_count
就可以了。
替换 {% if search.results == empty %}
,确定是否显示无结果文本,使用以下代码解决问题。
{% assign items_blank = 0 %}
{% for item in search.results %}
{% if item.featured_image == blank %}
{% assign items_blank = items_blank | plus: 1 %}
{% endif %}
{% endfor %}
{% if search.results == empty or items_blank == search.results_count %}
将{% if search.results == empty %}
行替换为以下代码
{% assign items_blank = 0 %}
{% for item in search.results %}
{% if item.featured_image == blank %}
{% assign items_blank = items_blank | plus: 1 %}
{% endif %}
{% endfor %}
{% if search.results == empty or items_blank == search.results_count %}