Ad

Shopify Blog Get More Than 50 Articles

- 1 answer

I have a shopify blog with over 150 articles in it

{% assign countItem = 0 %}
{% for article in blogs.recipes.articles %}
    {% if countItem < 3 %}
        {% if article.tags contains product.title %}
        {% assign countItem = countItem | plus: 1 %}
        <li class="article">
            <a target="_blank" rel="nofollow noreferrer" href="{{ article.url }}">
                <img src="{{ article | img_url: 'grande' }}" alt="{{ article.title }}" />
                <span class="title">{{ article.title }}</span>
            </a>
        </li>
        {% endif %}
    {% endif %}
{% endfor %}

However blogs.recipes.articles only returns 50.

Any way to remove this limitation?

Ad

Answer

Shopify limits the results to 50 so as to balance the server load. As per shopify docs.

Don't ever paginate a collection by more than 50, that's how many products maximum you should query per page. Be respectful of Shopify's app servers. If you are not using any paginate tags, pagination does kick in behind the scene and you will only receive the first 50 products in said collection.

However I have tried to load more than 50 products by using paginate tag. But that slows the page load and also the page may become unresponsive if the number of records is large. You can give it a try as following:-

{% paginate blogs.recipes.articles by 500 %}
{% assign countItem = 0 %}
{% for article in blogs.recipes.articles %}
{% if countItem < 3 %}
    {% if article.tags contains product.title %}
    {% assign countItem = countItem | plus: 1 %}
    <li class="article">
        <a target="_blank" rel="nofollow noreferrer" href="{{ article.url }}">
            <img src="{{ article | img_url: 'grande' }}" alt="{{ article.title }}" />
            <span class="title">{{ article.title }}</span>
        </a>
    </li>
    {% endif %}
{% endif %}
{% endfor %}
{% endpaginate %}
Ad
source: stackoverflow.com
Ad