Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Shopify 循环收集所选特定数量的产品_Shopify - Fatal编程技术网

Shopify 循环收集所选特定数量的产品

Shopify 循环收集所选特定数量的产品,shopify,Shopify,我是液体方面的新手(shopify) 我试图在一个周期内按特定数量的产品循环一个集合,但我的输出是错误的。 要理解,例如: 输出:首先是1-6的产品,然后是7-12的产品。但它只显示了该系列的前6款产品。任何人都可以在下面的代码中帮我一点忙吗?下面是我的代码: {% assign product_x_page = 6 %} {% assign product_number_in_collection = collection.all_products_count %} {% commen

我是液体方面的新手(shopify)

我试图在一个周期内按特定数量的产品循环一个集合,但我的输出是错误的。 要理解,例如:

输出:首先是1-6的产品,然后是7-12的产品。但它只显示了该系列的前6款产品。任何人都可以在下面的代码中帮我一点忙吗?下面是我的代码:

    {% assign product_x_page = 6 %}
{% assign product_number_in_collection = collection.all_products_count %}
{% comment %}{{ product_number_in_collection }}{% endcomment %}
{% assign number_of_pag_cycle = product_number_in_collection | divided_by: product_x_page %}
{% comment %}{{ number_of_pag_cycle }}{% endcomment %}

{% assign image_size = 'compact' %}
{% assign all_collection = 'related' %}
{% assign heading = 'You may also like' %}

{% if collection and collection.products_count > 1 %}
<h3 align="center">{{ heading }} of {{ collection.title }}</h3>
<br>

<div class="slickslide_container" role='toolbar'>  

{% assign ciclo = 0 %}

{% for loops in (1..number_of_pag_cycle) %}  

  <div> 

    <ul class="related-products">

    {% assign ciclo = ciclo | plus: 1 %}
    {{ciclo}}



    {% for product in collection.products %}

          <li>
            <div class="image">
              <a href="{{ product.url | within: collection }}" title="{{ product.title | escape }}">
                {{ product.featured_image | product_img_url: image_size | img_tag }}
              </a>
            </div>
            <h4><a href="{{ product.url }}" title="{{ product.title | escape }}">{{ product.title }}</a></h4>
            <span class="money">{{ product.price | money }}</span>
          </li>

    {% endfor %}
    </ul>   
  </div> 

{% endfor %}  


  {% endif %}
</div>
{%assign product\u x\u page=6%}
{%assign product\U number\U in\U collection=collection.all\U products\U count%}
{%comment%}{{product\u number\u in_collection}{%endcomment%}
{%assign number_of_pag_cycle=_集合中的产品_number_除以:产品_x_page%}
{%comment%}{{pag_循环数}{%endcomment%}
{%assign image_size='compact%}
{%assign all_集合='相关'%}
{%assign heading='您也可能喜欢“%”
{如果collection和collection.products_count>1%}
{{collection.title}的{{heading}}

{%assign ciclo=0%} {(1..u pag_循环的数量)%%中的循环的百分比}
    {%assign ciclo=ciclo | plus:1%} {{ciclo}} {%用于集合中的产品。产品%}
  • {{产品.价格|货币}
  • {%endfor%}
{%endfor%} {%endif%}
您可以使用
limit
参数查询前6个结果,如下所示:

{%用于集合中的产品。产品限制:6%}

您还可以使用名为
offset
的不同参数查询产品7到12,如下所示:

{%用于集合中的产品。产品偏移量:6%}

查看迭代标记的列表


如果您的目标是每页显示6个结果,请查看。

这里是我要求与slick.js一起使用的代码:

{% assign products_x_page = 6.0 %}
{% assign page_offset = 0 %}

{% assign product_number_in_collection = collection.products.size %}
{% comment %}{{ product_number_in_collection }}{% endcomment %}
{{ product_number_in_collection }}<br><br>

{% assign number_of_pag_cycle = product_number_in_collection | divided_by: products_x_page  %}
{% assign number_of_pag_cycle = number_of_pag_cycle | ceil %}
{% comment %}{{ number_of_pag_cycle }}{% endcomment %}
{{ number_of_pag_cycle }}


{% assign image_size = 'compact' %}
{% assign all_collection = 'related' %}
{% assign heading = 'You may also like' %}



{% if collection and collection.products_count > 1 %}

<h3 align="center">{{ heading }} of {{ collection.title }}</h3>
<br>

<div class="slickslide_container" role='toolbar'>  

{% assign ciclo = 0 %}

{% for loops in (1..number_of_pag_cycle) %} 

  {% if forloop.first == false %}
        {% assign page_offset = page_offset |plus: products_x_page %}
  {% endif %}
  {% comment %}{{page_offset}}{% endcomment %}

  <div> 

    <ul class="related-products">

    {% assign ciclo = ciclo | plus: 1 %}
    {% comment %}{{ciclo}}{% endcomment %}

    {% assign product_num = 0 %}


    {% for product in collection.products offset: page_offset %}

        {% assign product_num = product_num | plus: 1 %}


          <li>
            <div class="image">{% comment %}{{product_num}}{% endcomment %}
              <a href="{{ product.url | within: collection }}" title="{{ product.title | escape }}">
                {{ product.featured_image | product_img_url: image_size | img_tag }}
              </a>
            </div>
            <h4><a href="{{ product.url }}" title="{{ product.title | escape }}">{{ product.title }}</a></h4>
            <span class="money">{{ product.price | money }}</span>
          </li>

        {% if product_num == products_x_page %}
            {% break %}         
        {% endif %}

    {% endfor %}
    </ul>   
  </div> 

{% endfor %}  



</div>
{% endif %}  

<style type="text/css">
.related-products { list-style-type:none }
{% case image_size %}
{% when 'small' %}
.related-products * { font-size:12px; text-align:center; padding:0 }
.related-products h4  { border:none; margin:10px 0 0 0; line-height:1.3 }
.related-products div.image { height:100px }
.related-products li { float:left; width:120px; height:160px; margin-right:20px }
{% when 'compact' %}
.related-products * { font-size:13px; text-align:center; padding:0 }
.related-products h4  { border:none; margin:5px 0 0 0; line-height:1.5 }
.related-products div.image { height:160px }
.related-products li { float:left; width:220px; height:220px; margin-right:0px }
{% when 'medium' %}
.related-products * { font-size:14px; text-align:center; padding:0 }
.related-products h4  { border:none; margin:10px 0 0 0; line-height:1.8 }
.related-products div.image { height:240px }
.related-products li { float:left; width:260px; height:300px; margin-right:25px }
{% endcase %}
.related-products { overflow:hidden }
.related-products span.money { font-size:0.8em }
.related-products li:last-child { margin-right:0 }
</style>



  <script type='text/javascript'>
    $(function(){
      $('div.slickslide_container').slick({
        dots: true,
        infinite: false,
        speed: 300,
        slidesToShow: 1,
        adaptiveHeight: true
      });      
    });
  </script>
{%assign products\u x\u page=6.0%}
{%assign page_offset=0%}
{%assign product\U COLLATION=COLLATION.products.size%}
{%comment%}{{product\u number\u in_collection}{%endcomment%}
{{product_number_in_collection}}

{%assign number_of_pag_cycle=_集合中的产品_编号|除以:产品_x_page%} {%assign number_of_pag_cycle=number_of_pag_cycle|ceil%} {%comment%}{{pag_循环数}{%endcomment%} {{u-pag{u循环的个数} {%assign image_size='compact%} {%assign all_集合='相关'%} {%assign heading='您也可能喜欢“%” {如果collection和collection.products_count>1%} {{collection.title}的{{heading}}
{%assign ciclo=0%} {(1..u pag_循环的数量)%%中的循环的百分比} {%if-forloop.first==false%} {%assign page_offset=page_offset |加上:products_x_page%} {%endif%} {%comment%}{{page_offset}{%endcomment%}
    {%assign ciclo=ciclo | plus:1%} {%comment%}{{ciclo}{%endcomment%} {%assign product_num=0%} {%用于集合中的产品。产品偏移量:页\偏移量%} {%assign product_num=product_num加:1%}
  • {%comment%}{{product_num}{%endcomment%} {{产品.价格|货币}
  • {%if product_num==products_x_page%} {%break%} {%endif%} {%endfor%}
{%endfor%} {%endif%} .相关产品{列表样式类型:无} {%case image_size%} {%when'小'%} .相关产品*{字体大小:12px;文本对齐:居中;填充:0} .相关产品h4{边框:无;边距:10px 0;线高:1.3} .相关产品部门图片{高度:100px} .相关产品li{浮动:左;宽度:120px;高度:160px;右边距:20px} {%when'compact%} .相关产品*{字体大小:13px;文本对齐:居中;填充:0} .相关产品h4{边框:无;边距:5px 0 0;线条高度:1.5} .相关产品部门图片{高度:160px} .相关产品li{浮动:左;宽度:220px;高度:220px;右边距:0px} {%when'medium%} .相关产品*{字体大小:14px;文本对齐:居中;填充:0} .相关产品h4{边框:无;边距:10px 0;线高:1.8} .相关产品部门图片{高度:240px} .相关产品li{浮动:左;宽度:260px;高度:300px;右边距:25px} {%endcase%} .相关产品{溢出:隐藏} .相关产品span.money{font size:0.8em} .相关产品li:最后一个子项{页边距右侧:0} $(函数(){ $('div.slicklide_container')。光滑({ 点:是的, 无限:错, 速度:300,, 幻灯片放映:1, 自适应高度:真 }); });
您好,谢谢您的回复。我只是看到了关于抵销和限额的单据,但我无法解决我的问题:/i我想查询循环中的前6个产品,以及第二个循环表单7-12等,直到收款结束。可能吗?@JoeEverGreen我给你的密码就是这么做的。你的意思是每页要分页6种产品吗?嗨。谢谢你的回复。我试着更深入地解释;)。我想在同一页上循环,而不是每页。例如,我有一个标签,我希望前6个产品有这个标签,然后在同一页上有其他6个产品(7-12),并在收藏结束时继续。(不是每页而是同一页)。像这个模式页面(代码)。。。cicle on collection->cicle on 6个产品制作前6个标签->cicle next other 6个产品->关闭cicle collection希望你能帮助我;)谢谢你。最后,我用偏移解决方案解决了我的问题;)。我在下面添加代码。谢谢你的帮助