Shopify主题超级导航

Shopify超级导航

本文以Shopify免费主题Sense为例,修改header-mega-menu.liquid代码:(标粗

{% comment %}
  Renders a megamenu for the header.

  Usage:
  {% render 'header-mega-menu' %}
{% endcomment %}

<style>
.mega_img_container {
    position: relative;
}

.image_caption {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    color: #fff;
    padding: 5px;
    margin: 0;
}
</style>
<nav class="header__inline-menu">
  <ul class="list-menu list-menu--inline" role="list">
    {%- for link in section.settings.menu.links -%}
      <li>
        {%- if link.links != blank -%}
          <header-menu>
            <details id="Details-HeaderMenu-{{ forloop.index }}" class="mega-menu">
              <summary
                id="HeaderMenu-{{ link.handle }}"
                class="header__menu-item list-menu__item link focus-inset"
              >
                <span
                  {%- if link.child_active %}
                    class="header__active-menu-item"
                  {% endif %}
                >
                  {{- link.title | escape -}}
                </span>
                {% render 'icon-caret' %}
              </summary>
              <div
                id="MegaMenu-Content-{{ forloop.index }}"
                class="mega-menu__content color-{{ section.settings.menu_color_scheme }} gradient motion-reduce global-settings-popup"
                tabindex="-1"
              >
                <ul
                  class="mega-menu__list page-width{% if link.levels == 1 %} mega-menu__list--condensed{% endif %}"
                  role="list"
                >
                  {%- for childlink in link.links -%}
                    {% if childlink.title contains 'https://' or childlink.title contains 'http://' %}

                          {% assign img_url= childlink.title | split: '|' %}
                          
                          <li>
                          
                            <div class="mega_img_container">
                            
                              <a href="{{ childlink.url }}">
                              
                              <img src="{{ img_url[1] }}" style="width:150px;">
                              
                              <h4 class="image_caption">{{ img_url[0] }}</h4>
                              </a>
                            </div>

                        </li>

              {% else %}
                      
                    <li>
                      <a
                        id="HeaderMenu-{{ link.handle }}-{{ childlink.handle }}"
                        href="{{ childlink.url }}"
                        class="mega-menu__link mega-menu__link--level-2 link{% if childlink.current %} mega-menu__link--active{% endif %}"
                        {% if childlink.current %}
                          aria-current="page"
                        {% endif %}
                      >
                        {{ childlink.title | escape }}
                      </a>
                      {%- if childlink.links != blank -%}
                        <ul class="list-unstyled" role="list">
                          {%- for grandchildlink in childlink.links -%}

                          {% if grandchildlink.title contains 'https://' or grandchildlink.title contains 'http://' %}

                          {% assign grandchildlink_img_url= grandchildlink.title | split: '|' %}
                          
                          <li>
                          
                            <div class="mega_img_container">
                            
                              <a href="{{ grandchildlink.url }}">
                              
                              <img src="{{ grandchildlink_img_url[1] }}" style="width:150px;">
                              
                              <h4 class="image_caption">{{ grandchildlink_img_url[0] }}</h4>
                              </a>
                            </div>

                        </li>

              {% else %}
                            
                            <li>
                              <a
                                id="HeaderMenu-{{ link.handle }}-{{ childlink.handle }}-{{ grandchildlink.handle }}"
                                href="{{ grandchildlink.url }}"
                                class="mega-menu__link link{% if grandchildlink.current %} mega-menu__link--active{% endif %}"
                                {% if grandchildlink.current %}
                                  aria-current="page"
                                {% endif %}
                              >
                                {{ grandchildlink.title | escape }}
                              </a>
                            </li>
                            {%- endif -%}
                          {%- endfor -%}
                        </ul>
                      {%- endif -%}
                    </li>
                      {%- endif -%}
                  {%- endfor -%}
                </ul>
              </div>
            </details>
          </header-menu>
        {%- else -%}
          <a
            id="HeaderMenu-{{ link.handle }}"
            href="{{ link.url }}"
            class="header__menu-item list-menu__item link link--text focus-inset"
            {% if link.current %}
              aria-current="page"
            {% endif %}
          >
            <span
              {%- if link.current %}
                class="header__active-menu-item"
              {% endif %}
            >
              {{- link.title | escape -}}
            </span>
          </a>
        {%- endif -%}
      </li>
    {%- endfor -%}
  </ul>
</nav>

您可能还喜欢...