愿所有的美好和期待都能如约而至

如何将Shopify搜索输入限制为特定的集合?

发布时间:  来源:互联网  作者:匿名  标签:error How to limit Shopify search input to a specific collection? exception IT资讯  热度:37.5℃

本文介绍了如何将Shopify搜索输入限制为特定的集合?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试进行仅按集合中的结果进行搜索/筛选的搜索输入。

这是搜索模板:

<div id="col-main" class="page-search">

{% if search.results_count == 0 or search.performed == false %}
  <h4 class="title">{{ 'search.general.heading' | t: count: search.results_count }}: {{ 'search.general.results_with_count' | t: terms: search.terms, count: search.results_count }}</h4>

  <form class="search-form" action="/search">
    <input type="hidden" name="type" value="product" />
    <input type="hidden" name="options[prefix]" value="last" />
    <input type="text" name="q" class="search_box" placeholder="{{settings.search_placeholder}}" value="{{ search.terms }}" />

    <button type="submit" class="search-submit" title="Search">
      {% if settings.search_icon_type == 'font-icon' %}
        <i class="demo-icon {{ settings.search_font_icon }}"></i>
      {% else %}
        <img src="{{ settings.search_icon | img_url: '20x' }}" alt="Search" />
      {% endif %}
    </button>
  </form>

{% else %}
  {% if search.performed %}
    {% paginate search.results by 16 %}

    <h4 class="title">{{ 'search.general.heading' | t: count: search.results_count }}: {{ 'search.general.results_with_count' | t: terms: search.terms, count: search.results_count }}</h4>

    <div class="cata-product cp-grid">
      {% for product in search.results %}
        {% if product.object_type == 'product' %}
          <div class="product-grid-item">
            {% include 'product-item' %}
          </div>
        {% else %}
          <div class="article-grid-item">
            {% include 'article-result' %}
          </div>
        {% endif %}
      {% endfor %}
    </div>

    {% if paginate.pages > 1 %}
      {% include 'pagination' %}
    {% endif %}

    {% endpaginate %}
  {% endif %}

{% endif %}

如何将其编辑为仅在与”已用”匹配的集合名称中进行搜索?

有shopify collection object,但不知道是否应该尝试编辑:

<input type="text" name="q" class="search_box" placeholder="{{settings.search_placeholder}}" value="{{ search.terms }}" />

或搜索结果

{% for product in search.results %}

如有任何帮助我们将不胜感激,谢谢

推荐答案

获取所有结果、筛选、生成;问题是分页,我目前没有解决方案。

{% paginate search.results by search.results_count %}
  {% for item in search.results %}
    {% if item.object_type == 'product' %}
      {% for collection in item.collections %}
        {% if collection.title contains 'myCollectionTitle' %}
          {% assign image = item.featured_image | img_url: 'medium' %}
          
          <a href="{{item.url}}">{{item.title}} <img src="{{image}}" alt="" class="" loading="lazy" width="" height=""></a><br>
          {% endif %}
      {% endfor %}
    {% endif %}
  {% endfor %}  
{% endpaginate %}

这篇关于如何将Shopify搜索输入限制为特定的集合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,

勇敢去编程!

勇敢的热爱编程,未来的你一定会大放异彩,未来的生活一定会因编程更好!

TOP