Advertisement
Coding_with_Jan

Featured Collection Slider for Shopify Themes

May 2nd, 2021 (edited)
16,976
1
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.70 KB | None | 1 0
  1. codingwithjan.com // Featured Collection Slider for Shopify Themes
  2.  
  3. Theme.liquid
  4. ---------------------------------------
  5. <!-- make sure to read up on the Flickity licenses -->
  6. <link rel="stylesheet" href="https://unpkg.com/flickity@2/dist/flickity.min.css">
  7. <script src="https://unpkg.com/flickity@2/dist/flickity.pkgd.min.js"></script>
  8.  
  9.  
  10.  
  11. Collection-slider.liquid
  12. ---------------------------------------
  13.  
  14. {%- capture flickity_options -%}
  15. {
  16.   "prevNextButtons": true,
  17.   "pageDots": false,
  18.   "contain": true,
  19.   "cellAlign": "left",
  20.   "groupCells": true,
  21.   "arrowShape": {"x0": 20, "x1": 60, "y1": 40, "x2": 60, "y2": 35, "x3": 25}
  22. }
  23. {%- endcapture -%}
  24.  
  25. <div class="featured-collection-slider page-width">
  26. {% if section.settings.title != blank %}
  27. <div class="section-header text-center">
  28.   <h2>{{ section.settings.title | escape }}</h2>
  29. </div>
  30. {% endif %}
  31.  
  32. {%- assign collection = collections[section.settings.collection] -%}
  33. {%- assign product_limit = section.settings.product_count -%}
  34.  
  35.     <div class="products-carousel js-flickity" data-flickity='{{ flickity_options }}'>
  36.       {% for product in collection.products limit: product_limit %}
  37.         <div class="carousel-cell">
  38.           <a href="{{ product.url | within: collection }}">
  39.             <img class="img-explore" src="{{ product.featured_image | img_url: 'master'}}">
  40.             <h4>{{ product.title }}</h4>
  41.             <p>{{ product.price | money }}</p>
  42.           </a>
  43.       </div>  
  44.     {% endfor %}
  45.     </div>
  46. </div>
  47.  
  48. <style>
  49. .featured-collection-slider{
  50.   padding-left: 55px;
  51.   padding-right: 55px;
  52.   max-width: 1200px;
  53.   margin: 0 auto;
  54. }
  55. .featured-collection-slider .carousel-cell{
  56.   width:25%;
  57.   padding: 0 15px;
  58.   display: block;
  59. }
  60. .flickity-button:disabled{
  61.   pointer-events: all!important;
  62. }
  63. @media screen and (max-width: 920px){
  64.   .featured-collection-slider{
  65.     padding-left: 15px;
  66.     padding-right: 15px;
  67.   }
  68.   .featured-collection-slider .carousel-cell{
  69.     width:50%;
  70.   }
  71. }
  72. @media screen and (max-width: 767px){
  73.   .featured-collection-slider .carousel-cell{
  74.     width:100%;
  75.   }
  76. }
  77. </style>
  78.  
  79. {% schema %}
  80. {
  81.   "name": "Collection Slider",
  82.   "settings": [
  83.     {
  84.       "type": "text",
  85.       "id": "title",
  86.       "label": "Heading",
  87.       "default": "Featured Collection"
  88.     },
  89.     {
  90.       "type": "collection",
  91.       "id": "collection",
  92.       "label": "Collection"
  93.     },
  94.     {
  95.       "type": "range",
  96.       "id": "product_count",
  97.       "min": 4,
  98.       "max": 12,
  99.       "label": "Number of products to display",
  100.       "default": 4
  101.     }
  102.   ],
  103.   "presets": [
  104.     {
  105.       "category": "Collection",
  106.       "name": "Collection Slider",
  107.       "settings": {}
  108.     }
  109.   ]
  110. }
  111. {% endschema %}
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement