您谈论的是Storefront,但您提供的是Admin API URL。如果不使用GraphQL或Rest API,就无法从店面请求管理员!
You are limited by 50 articles if you don't overwrite the paginate on the storefront.
But if you overwrite it you can get as much as you like. ( have in mind that the larger the article pool the longer the DOM will load )
Example:
{% paginate blog.articles by 9999 %}
{% for article in blog.articles %}
{% endfor %}
{% endpaginate %}
You can create a separate blog template and request it with AJAX and add the tag to the end as well.
So if you create a blog template called blog.ajax.liquid
your request will be something like so: /blogs/news/tagged/featured?view=ajax
and it will return the html for the new template filtered by the tag featured
.
The other way is to use the storefront GraphQL in order to get the articles.
You will need to create a private app and allow Read content like articles, blogs, and comments
in order to use this.
Example query:
{
blogByHandle(handle:"news"){
articles(first: 50, query:"tag:featured") {
edges {
node {
title
}
}
}
}
}
当然,这将返回50个带有名为标记的文章标题featured
,您可以添加更多您希望查询返回的字段。
另一种方法是使用REST API。
您仍然需要创建一个私有应用程序,但是您必须仅允许“博客和文章”阅读权限,而没有写权限。此外,应禁用所有其他权利,以免其他人修改您的商店数据。
AJAX网址将如下所示: https://API_KEY:API_PASSWORD@YOUR_STORE.myshopify.com/admin/api/2020-01/blogs/BLOG_ID/articles.json?tag=featured
我不推荐这种方法,但是仍然可以。
在这里,您可以选择自己喜欢的方式。
好答案。感谢您深入了解。老实说,这比Shopify文档要好。我根据您对Liquid页面的建议解决了该问题。
@Modermo没问题。请记住,如果您发布的帖子数量过多(1000+),则此请求的时间可能会增加很多(最多5-10秒甚至更多)。其他方法没有这个问题,但是需要了解GraphQL或Rest API。祝好运!