ruby - Is it possible to dynamically set the "featured" collection on a shopify store? -
i able display 2 different collections in featured products section on shopify store. avoid displaying featured product same product being viewed. see on customize theme page possible chose collection displayed, collection cannot change. believe best way use product tags , change featured collection based on tag. have not had success. here appreciated.
{% tag in product.tags %} {% if tag contains 'top' %} {% assign settings.home_featured_products == 'home' %} {% elsif tag contains 'bottom' %} {% assign settings.home_featured_products == 'frontpage' %} {% endif %} {% endfor %} there "featured-products.liquid" file included on product page controls layout of featured products section. may possible create 2 of these files show 2 different collections , display different files based on tags. not sure how control collection displayed in file.
<!-- snippets/featured-products.liquid --> {% if section_number > 1 , number_of_index_sections > 1 %} <hr class="hr--medium hr--clear"> {% endif %} <div class="section-header text-center"> <h1>{{ 'home_page.sections.featured_products' | t }}</h1> <hr class="hr--small"> </div> <div class="{% if settings.collection_products_grid == 'collage' %}grid grid-collage{% else %}grid-uniform{% endif %}"> {% comment %} loop through products in frontpage collection. collection created default, must add products it. see snippet 'snippets/product-grid-collage.liquid'. `is_reverse_row_product`, `three_row_index_product`, `collection_product_count_product`, , `divisible_by_three_product` used 'snippets/product-grid-collage.liquid' {% endcomment %} <div class="grid-uniform__aligner"> {% if settings.home_featured_products == blank or collections[settings.home_featured_products].empty? or collections[settings.home_featured_products].products_count == 0 %} {% comment %} onboarding new users theme, add default products , onboarding tutorials populate store {% endcomment %} {% unless emptystate %} {{ 'theme-onboarding.css' | global_asset_url | stylesheet_tag }} {% assign emptystate = true %} {% endunless %} {% include 'onboarding-featured-products' %} {% else %} {% if settings.collection_products_grid == 'collage' %} {% assign is_reverse_row__product = false %} {% assign three_row_index__product = 0 %} {% if collections[settings.home_featured_products].products_count > 50 %} {% assign collection_product_count__product = 50 %} {% else %} {% assign collection_product_count__product = collections[settings.home_featured_products].products_count %} {% endif %} {% assign divisible_by_three__product = collection_product_count__product | modulo:3 %} {% product in collections[settings.home_featured_products].products %} {% include 'product-grid-collage' %} {% endfor %} {% else %} {% assign grid_item_width = 'medium--one-half large--one-third' %} {% product in collections[settings.home_featured_products].products %} {% include 'product-grid-item' %} {% endfor %} {% endif %} {% endif %} </div> </div>
if want not display current product in collection can this:
{% assign handle = product.handle %} {% product in collection[featured_products].products %} {% unless product.handle == handle %} product goes here. {% endunless %} {% endfor %} you can replace 'your product goes here.' of product objects specified here
Comments
Post a Comment