For Loop to control number of items to display

Sheikh_Zaman
New Member
4 0 0

I hope someone can help me with this. I am using Mobilia theme and I am trying to display only 8 items in the first page. I was hoping by adding this line (   { % for content in pages[settings.featured_content_page].content limit:8 offset:0 % }) into theme.liquid would give me the expected result. But, it didn't work. Any help would be appreciated.

        {% if settings.featured_content_page != blank %}
         <div class="sixteen columns alpha omega">
            <div class="section clearfix featured_content">
              { % for content in pages[settings.featured_content_page].content limit:8 offset:0 % }
              {{ pages[settings.featured_content_page].content }}
              { %  endfor %}
            </div>
          </div>
        {% endif %}

0 Likes
Jason
Shopify Expert
10035 119 1871

Your loop is a little messed up, but we'll fix it. It looks like you are trying to loop over a single page but that's not going to work for you. If you are trying to show items from a collection you would loop over a collection and not a page. 

{% for product in collections.frontpage.products limit:8 %} 
    {{ product.title }} 
{% endfor %}

See the collection page for more info.

★ Winning Partner of the Build a Business competition. ★ http://freakdesign.com.au
Sheikh_Zaman
New Member
4 0 0

Hi Jason,

Thank you for your reply.  The following piece of code is working correctly, but I am trying to limit the number of items.

{{ pages[settings.featured_content_page].content }}

 

I have also tried to add the handle (art) with the following code but no luck.
{% for product in collections.art.products limit:8 %}

0 Likes
Jason
Shopify Expert
10035 119 1871
{{ pages[settings.featured_content_page].content }}

Each page has one piece of content (the text entered into the editor) and that's what you pulling out here.

If you do have a collection with the handle of art this will do something.

{% for product in collections.art.products limit:8 %}
    <h2>{{ product.title }}</h2>
    {{ product.description }}
{% endfor %}

 

★ Winning Partner of the Build a Business competition. ★ http://freakdesign.com.au
0 Likes
Sheikh_Zaman
New Member
4 0 0

Yes, it returned product title and description. How do I return/display product images instead?

0 Likes
Jason
Shopify Expert
10035 119 1871

Check out the product wiki -- it will give you an idea of the variables you have access to for products.

<img src="{{ product.featured_image | product_img_url: 'small' }}" />

 

★ Winning Partner of the Build a Business competition. ★ http://freakdesign.com.au
0 Likes
Sheikh_Zaman
New Member
4 0 0

Awesome. Thank you very much. 

0 Likes
Gayatri_Jain
New Member
1 0 0

Thanks... It helped me to get required number of returns.

0 Likes