Add Tab Blog Image

blog-tabs-gallery.liquid
{{ 'tzn_gallery_tabs.css' | asset_url | stylesheet_tag }}
{% style %}
  .section-{{ section.id }}-padding {
    padding-top: {{ section.settings.padding_top | divided_by: 16.0 }}rem;
    padding-bottom: {{ section.settings.padding_bottom | divided_by: 16.0 }}rem;
  }

  @media screen and (min-width: 62rem) {
    .section-{{ section.id }}-padding {
      padding-top: {{ section.settings.padding_top | divided_by: 16.0 }}rem;
      padding-bottom: {{ section.settings.padding_bottom | divided_by: 16.0 }}rem;
    }
  }

 

  .gallery-tabs .tab-btn {
    background-color: #fff;
    border: 1px solid #ccc;
    padding: 0.5rem 1rem;
    cursor: pointer;
  }

  .gallery-tabs .tab-btn.active {
    background-color: #D7CDBF;
  }

  .gallery-tabs .tab-content {
    display: none;
  }

  .gallery-tabs .tab-content.active {
    display: block;
  }

  .gallery-tabs .custom-swiper {
    overflow: hidden;
  }

  .gallery-tabs .swiper-slide {
    width: calc(25% - 1rem);
    margin-right: 1rem;
  }

  .gallery-tabs .image-list {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
  }

  .gallery-tabs .image-item {
    width: calc(25% - 1rem);
  }

{% endstyle %}

<section class="gallery-tabs section-{{ section.id }}-padding color-{{ section.settings.color_scheme }}{% if section.settings.align != blank %} center-content{% endif %}">
  <div class="page-width scroll-trigger animate--slide-in">
    {% if section.settings.title != blank %}
      <h2 class="title mb0">{{ section.settings.title }}</h2>
    {% endif %}
    {% if section.settings.subheading != blank %}
      <div class="subtitle">{{ section.settings.subheading }}</div>
    {% endif %}
    {% if section.settings.content != blank %}
      <div class="content">{{ section.settings.content }}</div>
    {% endif %}

    <div class="tab-buttons" id="tab-buttons">
      {% assign blog_handles = '' %}
      {% for block in section.blocks %}
        {% assign handle = block.settings.blog.handle %}
        {% unless blog_handles contains handle %}
          <button class="tab-btn button button--secondary " data-tab="{{ handle }}">{{ block.settings.blog.title }}</button>
          {% assign blog_handles = blog_handles | append: handle | append: ',' %}
        {% endunless %}
      {% endfor %}
    </div>

    <div class="tab-contents" id="tab-contents">
      {% assign handles_array = blog_handles | split: ',' | uniq %}
      {% for handle in handles_array %}
        {% if handle != '' %}
          {% assign blog = blogs[handle] %}
          {% assign articles = blog.articles %}
          {% assign count = articles.size %}

          <div class="tab-content{% if count > 4 %} has-gallery-swiper{% endif %}" data-tab="{{ handle }}">
            {% if count > 4 %}
              <div class="gallery-swiper swiper">
                <div class="swiper-wrapper">
                  {% for article in articles %}
                    <div class="swiper-slide">
                      <a href="{{ article.url }}">
                                 <img src="{{ article.image | image_url }}" alt="{{ article.title }}">
                      </a>
                    </div>
                  {% endfor %}
                </div>
                <div class="swiper-pagination"></div>
                <div class="swiper-button-next gallery-swiper-next">
                    {{ 'arrow-left.svg' | inline_asset_content }}
                </div>
                <div class="swiper-button-prev gallery-swiper-prev">
                    {{ 'arrow-left.svg' | inline_asset_content }}
                </div>
              </div>
            {% else %}
              <div class="image-list">
                {% for article in articles %}
                  <div class="image-item">
                    <a href="{{ article.url }}">
                      <img src="{{ article.image | image_url: 'medium' }}" alt="{{ article.title }}">
                      <p>{{ article.title }}</p>
                    </a>
                  </div>
                {% endfor %}
              </div>
            {% endif %}
            <div class="center view-more">
              <a class="button button--primary" href="{{ blog.url }}">
                Mehr erfahren
              </a>
            </div>
          </div>
        {% endif %}
      {% endfor %}
    </div>
  </div>

  <script>
    document.addEventListener('DOMContentLoaded', function () {
      const buttons = document.querySelectorAll('.tab-btn');
      const contents = document.querySelectorAll('.tab-content');

      function activateTab(id) {
        buttons.forEach(btn => {
          btn.classList.toggle('active', btn.dataset.tab === id);
        });

        contents.forEach(content => {
          content.classList.toggle('active', content.dataset.tab === id);
        });

        const content = document.querySelector(`.tab-content[data-tab="${id}"]`);
        if (
          content &&
          content.classList.contains('has-gallery-swiper') &&
          !content.classList.contains('swiper-initialized')
        ) {
          new Swiper(content.querySelector('.gallery-swiper'), {
            loop: true,
            slidesPerView: 4,
            spaceBetween: 16,
            pagination: {
              el: content.querySelector('.swiper-pagination'),
              clickable: true,
            },
            navigation: {
              nextEl: content.querySelector('.gallery-swiper-next'),
              prevEl: content.querySelector('.gallery-swiper-prev'),
            },
             breakpoints: {
                0: {
                slidesPerView: 2,
                },
                768: {
                slidesPerView: 4,
                }
            }
          });
          content.classList.add('swiper-initialized');
        }
      }

      if (buttons.length > 0) {
        activateTab(buttons[0].dataset.tab);
      }

      buttons.forEach(btn => {
        btn.addEventListener('click', () => {
          activateTab(btn.dataset.tab);
        });
      });
    });
  </script>
</section>



{% schema %}
{
  "name": "Gallery Blog Custom ",
  "tag": "section",
  "settings": [
    {
      "type": "text",
      "id": "title",
      "label": "Title"
    },
    {
      "type": "text",
      "id": "subheading",
      "label": "Subheading"
    },
    {
      "type": "richtext",
      "id": "content",
      "label": "Content"
    },
    {
      "type": "color_scheme",
      "id": "color_scheme",
      "label": "Color Scheme"
    },
    {
      "type": "range",
      "id": "padding_top",
      "min": 0,
      "max": 120,
      "step": 8,
      "unit": "px",
      "default": 40,
      "label": "Padding Top"
    },
    {
      "type": "range",
      "id": "padding_bottom",
      "min": 0,
      "max": 120,
      "step": 8,
      "unit": "px",
      "default": 40,
      "label": "Padding Bottom"
    }
  ],
  "blocks": [
    {
      "type": "blog_tab",
      "name": "Blog Tab",
      "settings": [
        {
          "type": "blog",
          "id": "blog",
          "label": "Select Blog"
        }
      ]
    }
  ],
  "presets": [
    {
      "name": "Gallery Custom ",
      "category": "Custom"
    }
  ]
}
{% endschema %}

tzn_gallery_tabs.css
h2.title.mb0 {
    margin: 0;
}
.center-content .subtitle,
.center-content .content,
.center-content h2{
  text-align: center;
}
.center-content .content{
  max-width: 45.75rem;
  margin: 1.25rem auto 0;
}
div#tab-buttons>* {
    /* max-width: 25%; */
    width: 100%;
    text-transform: capitalize;
    max-width: calc(25% - .625rem);
    width: 100%;
    text-transform: capitalize !important;
}
.center.view-more {
    margin-top: 2.5rem;
}
div#tab-buttons > *:hover{
    background-color: #D7CDBF !important;
}
div#tab-contents .swiper-pagination.swiper-pagination-bullets {
    display: none;
}
div#tab-contents {
    position: relative;
}
div#tab-contents  .swiper-button-prev {
    left: -2.5rem;
}
div#tab-contents  .swiper-button-next {
    right: -2.5rem;
}
div#tab-buttons {
    margin-top: 2.5rem;
    margin-bottom: 1.25rem;
    display: flex; 
    justify-content: space-between;
    gap: .625rem;
    flex-flow: row wrap;
    justify-content: center;
}
.image-item img,
.gallery-tabs div#tab-contents img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scale(1);
    transition: all 1s;
}
.image-item:hover img, .gallery-tabs div#tab-contents .swiper-slide:hover img {
    transform: scale(1.15) !important;
}
.gallery-tabs div#tab-contents .swiper-slide {
    width: 388px;
    height: 23.375rem;
    background: #FFFFFF;
    box-shadow: 0px 3px 10px #0000002E;
    padding: 1.125rem;
    overflow: hidden;
}
.image-item{
    height: 23.375rem;
    background: #FFFFFF;
    box-shadow: 0px 3px 10px #0000002E;
    padding: 1.125rem;
    overflow: hidden;
}
.image-list {
    display: flex;
    gap: .625rem;
}
.image-list>* {
    width: 100%;
    max-width: 100%;
    flex: 1;
}
@media screen and (max-width: 990px){ 
  .image-item {
    height: 280px;
    padding: 10px;
  }
  .image-list {
    display: grid;
    gap: .625rem;
    grid-template-columns: 1fr 1fr;
  }
   div#tab-contents .swiper-button-prev,
   div#tab-contents .swiper-button-next {
    display: none;
  }
  .gallery-tabs div#tab-contents .swiper-slide {
    height: 280px;
    padding: 10px;
  }
  .gallery-tabs .page-width {
    max-width: 428px;
  }
  .gallery-tabs {
    padding-top: 50px !important;
    padding-bottom: 50px !important;
  }
  div#tab-buttons>* {
    max-width: 100%;
    width: 100%;
    text-transform: inherit;
  }
  div#tab-buttons {
      display: grid;
      justify-content: space-between;
      gap: 20px;
      flex-wrap: wrap;
      max-width: 261px;
      margin: 30px auto;
      grid-template-columns: 1fr;
  }
  .center.view-more {
    margin-top: 30px;
  }
  .tab-content.swiper-container {
    padding-bottom: 25px;
  }
  div#tab-contents .swiper-pagination.swiper-pagination-bullets {
    display: flex;
  }
}

Leave a Reply

Your email address will not be published. Required fields are marked *