简体   繁体   English

Shopify Liquid:第一个博客页面上的帖子数量不同

[英]Shopify Liquid: Different number of posts on first blog page

I'm working in blog-template.liquid.我在 blog-template.liquid 工作。 I'm trying to show 13 articles on the first page of the blog with subsequent pages showing 12. My initial attempt was this:我试图在博客的第一页显示 13 篇文章,随后的页面显示 12 篇。我最初的尝试是这样的:

{% if paginate.current_page > 1 %}
  {% paginate blog.articles by 12 %}
{% else %} 
  {% paginate blog.articles by 13 %}
{% endif %} 

 // Output articles...
{% endpaginate %}

This doesn't work because {% endpaginate %} must be paired with 'paginate' inside the if/else statement.这不起作用,因为 {% endpaginate %} 必须与 if/else 语句中的 'paginate' 配对。

I've attempted the code below using variables but Shopify rejects the variable usage with 'Unknown tag 'num_articles'.我尝试使用变量来编写下面的代码,但 Shopify 拒绝使用“未知标签‘num_articles’”的变量。 Is there any way to have this statement accept and transform a variable to an integer – or is there a different solution I'm not thinking of?有没有办法让这个语句接受一个变量并将其转换为 integer——或者有没有我没有想到的不同解决方案? I'm somewhat new to Shopify and Liquid.我对 Shopify 和 Liquid 有点陌生。

{% assign num_articles = 13 %}

{% if paginate.current_page > 1 %}
  {% num_articles = 12 %}
{% endif %} 

{% paginate blog.articles by num_articles %}
 // Output articles...
{% endpaginate %}

No, you cannot do that.不,你不能那样做。 Pagination tag works with the for tag to split content into many pages by setting the limit offset . Pagination标签配合for标签,通过设置limit offset将内容分成多页。 This offset is fixed (constant) within pagination.此偏移量在分页中是固定的(常量)。

There are ugly work around and with Shopify API you can try.有一些丑陋的解决方法,您可以尝试使用Shopify API go search around for pagination offset. go 搜索分页偏移量。

https://shopify.dev/api/liquid/objects/paginate https://shopify.dev/api/liquid/objects/paginate

Paginate Shopify blog with offset? 使用偏移量对 Shopify 博客进行分页? (Liquid) (液体)

https://community.shopify.com/c/shopify-discussions/how-to-offset-the-second-page-in-a-collection/td-p/41939 https://community.shopify.com/c/shopify-discussions/how-to-offset-the-second-page-in-a-collection/td-p/41939

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM