Product Loop Counter and Center Last Product if Odd

Open up product-list.liquid

Outside of product loop assign variable for counter

 Screen Shot 2017-06-21 at 1.05.09 PM

Inside the product loop, assign plus 1 counter

Go inside product-loop.liquid

Screen Shot 2017-06-21 at 1.06.38 PM

Inside product parent div, add cycle class with "odd" and "even"

Wrap up cycle class with captured "is_it_odd" variable

Assign a "product-is" class variable to the output of "is_it_odd"

Assign a "product_number" class variable to the output of "product-loop-count" from previous liquid file

Create if statement, if forloop.last = true, add class of last product.

Create if statement inside of previous if statement, if it's odd and the last product, add class of col-md-offset-3

{% capture is_it_odd %}{% cycle 'odd', 'even' %}{% endcapture %} product-is-{{ is_it_odd }} product_number-{{ product-loop-count }} {% if forloop.last == true %}last-product {% if is_it_odd == 'odd' %}col-md-offset-3{% endif %}{% endif %} 

Leave a comment