How can I insert an image gallery section in my homepage using liquid code?

How can I insert an image gallery section in my homepage using liquid code?

Jcox1981
Excursionist
28 0 6

Hi Guys,

 

I would like to insert an image gallery section in my template homepage, with a maximum of 4 images in a row which i can add links to product pages. Desktop mock up:

 

Screenshot 2020-05-16 at 10.22.56.png

 

Ideally the gallery will then adjust to two in a row for mobile. Mobile mock up:

 

Screenshot 2020-05-16 at 10.23.52.png

 

Does anyone have any liquid code i can use to create a new image gallery in my template homepage please?

 

Or, if anyone knows another way i can do this, that would also be great! 

 

Thanks so much for any help you can give!!

 

 

Replies 16 (16)

KetanKumar
Shopify Partner
37618 3670 12165

@Jcox1981 

Thanks for post 

Please share your site URL,
So I will check and provide a solution here.

If helpful then please Like and Accept Solution. Partnership of your ️ Coffee Tips and my code can bring miracles.
Want to modify or custom changes on store Hire Me.
- Feel free to contact me on bamaniyaketan.sky@gmail.com regarding any help Shopify Partner | Skype : bamaniya.sky
PSD to Shopify | Shopify Design Changes | Shopify Custom Theme Development and Desing | Custom Modifications In to Shopify Theme | SEO & Digital Marketing
Jcox1981
Excursionist
28 0 6

Hi Ketan

 

I have realised that i actually already have this section in my template. However, i only have the ability to have 3 images. Is there a way i can change the liquid file below so that i can have 4?

 

Many thanks

 

<div data-section-id="{{ section.id }}" data-section-type="featured-images">

  {% assign sectionBorder = section.settings.border %}
  {% assign textShadow = section.settings.text-shadow %}

  {% if section.blocks.size == 0 %}
    {% assign featureCount = 2 %}
  {% else %}
    {% assign featureCount = 0 %}
    {% for block in section.blocks %}
      {% assign featureCount = featureCount | plus: 1 %}
    {% endfor %}
  {% endif %}

  <div class="home-module home-feature-row
    row-of-{{featureCount}} text-shadows-{{ textShadow }}
    {% if sectionBorder %}has-border{% endif %}">

    <div class="home-module-content {% if section.settings.title != blank %}home-module-has-heading{% endif %}">

      {%
        include 'home-section-title',
        sectionTitle: section.settings.title,
      %}

      <div class="home-module-inline-items">
        {% if section.blocks.size > 0 %}
          {% for block in section.blocks %}
            {% assign textAbove = block.settings.text-above | escape %}
            {% assign heading = block.settings.title | escape %}
            {% assign textBelow = block.settings.text-below | escape %}
            {% assign url = block.settings.url %}
            {% assign textColor = block.settings.text-color %}
            {% assign textPosition = block.settings.text-position %}
            {% assign image = block.settings.image %}

            {%- capture image_html -%}
              {% if image %}
                {%
                  include 'rimg',
                  img: image,
                  size: '1440x640',
                  lazy: true
                %}
              {% else %}
                {{ 'collection-1' | placeholder_svg_tag: 'placeholder-svg' }}
              {% endif %}
            {%- endcapture -%}

            <div class="home-feature">
              <div class="home-feature-image">
                {{- image_html -}}
              </div>

              {% if url != blank %}
                <a class="home-feature-link" href="{{ url }}"></a>
              {% endif %}

              {% if textAbove != blank or heading != blank or textBelow != blank %}
                <div class="home-feature-content text-color-{{ textColor }} text-positioned-{{ textPosition }} rte">
                  {% if textAbove != blank %}
                    <p>{{ textAbove }}</p>
                  {% endif %}

                  {% if heading != blank %}
                    <h3>{{ heading }}</h3>
                  {% endif %}

                  {% if textBelow != blank %}
                    <p>{{ textBelow }}</p>
                  {% endif %}
                </div>
              {% endif %}
            </div>
          {% endfor %}
        {% else %}
          {% for i in (1..2) %}
            <div class="home-feature">
              <div class="home-feature-image">
                {% capture current %}{% cycle 1, 2 %}{% endcapture %}
                {{ 'collection-' | append: current | placeholder_svg_tag: 'placeholder-svg' }}
              </div>

              <a class="home-feature-link" href="#"></a>

              <div class="home-feature-content text-color-dark text-positioned-center rte">
                <p>{{ 'onboarding.featured_images.text_above' | t }}</p>
                <h3>{{ 'onboarding.featured_images.title' | t }}</h3>
                <p>{{ 'onboarding.featured_images.text_below' | t }}</p>
              </div>
            </div>
          {% endfor %}
        {% endif %}
      </div>

    </div>
  </div>

</div>

{% schema %}
{
  "name": "Gallery",
  "max_blocks": 3,
  "settings": [
    {
      "type": "text",
      "id": "title",
      "label": "Heading",
      "default": "Image gallery"
    },
    {
      "type": "checkbox",
      "id": "border",
      "label": "Show border",
      "default": false
    },
    {
      "type": "checkbox",
      "id": "text-shadow",
      "label": "Show text shadow",
      "info": "Only appears when \"text shade\" is set to \"light\"."
    }
  ],
  "blocks": [
    {
      "type": "feature",
      "name": "Image",
      "settings": [
        {
          "type": "image_picker",
          "id": "image",
          "label": "Image",
          "info": "1440 x 640px .jpg recommended"
        },
        {
          "type": "text",
          "id": "title",
          "label": "Heading",
          "default": "Image with text"
        },
        {
          "type": "text",
          "id": "text-above",
          "label": "Subheading",
          "default": "Subheading"
        },
        {
          "type": "text",
          "id": "text-below",
          "label": "Text",
          "default": "Text"
        },
        {
          "type": "url",
          "id": "url",
          "label": "Link"
        },
        {
          "type": "select",
          "id": "text-color",
          "label": "Text shade",
          "options": [
            {
              "value": "light",
              "label": "Light"
            },
            {
              "value": "dark",
              "label": "Dark"
            }
          ],
          "default": "light"
        },
        {
          "type": "select",
          "id": "text-position",
          "label": "Align text",
          "options": [
            {
              "value": "left",
              "label": "Left"
            },
            {
              "value": "center",
              "label": "Center"
            },
            {
              "value": "right",
              "label": "Right"
            }
          ],
          "default": "center",
          "info": "Will default to \"center\" if three features are shown in a row."
        }
      ]
    }
  ],
  "presets": [
    {
      "category": "Image",
      "name": "Gallery",
      "blocks": [
        {
          "type": "feature"
        },
        {
          "type": "feature"
        }
      ]
    }
  ]
}

{% endschema %}
adventmedia
Pathfinder
128 0 31

Did you successfully create the gallery? Can you share the code?

KetanKumar
Shopify Partner
37618 3670 12165

@adventmedia 

Sorry you are facing this issue, it would be my pleasure to help you.

Welcome to the Shopify community!😊
Thanks for your good question.

Please share your site URL,
I will check out the issue and provide you a solution here.

If helpful then please Like and Accept Solution. Partnership of your ️ Coffee Tips and my code can bring miracles.
Want to modify or custom changes on store Hire Me.
- Feel free to contact me on bamaniyaketan.sky@gmail.com regarding any help Shopify Partner | Skype : bamaniya.sky
PSD to Shopify | Shopify Design Changes | Shopify Custom Theme Development and Desing | Custom Modifications In to Shopify Theme | SEO & Digital Marketing
adventmedia
Pathfinder
128 0 31
KetanKumar
Shopify Partner
37618 3670 12165

@adventmedia 

yes i can see its proper what' issue?

If helpful then please Like and Accept Solution. Partnership of your ️ Coffee Tips and my code can bring miracles.
Want to modify or custom changes on store Hire Me.
- Feel free to contact me on bamaniyaketan.sky@gmail.com regarding any help Shopify Partner | Skype : bamaniya.sky
PSD to Shopify | Shopify Design Changes | Shopify Custom Theme Development and Desing | Custom Modifications In to Shopify Theme | SEO & Digital Marketing
haziqulhassan
Shopify Partner
3 0 0
"name": "Gallery",
  "max_blocks": 3,
  "settings": [
    {
      "type": "text",
      "id": "title",
      "label": "Heading",
      "default": "Image gallery"
    },

here "max_blocks" :3 changed To "max_blocks": 4
thanks

shopevermore
Visitor
1 0 1

Hi! I am trying to add the same image gallery section to my shopify theme but I am having trouble. I copied and pasted the exact code into my section liquid but when I try to add the section to the theme, I keep getting this first error. And when I try to upload a picture to the image gallery, I keep getting this second error. Really need some help, thank you.adding section to theme.pngadding image.png

KetanKumar
Shopify Partner
37618 3670 12165

@shopevermore 

Sorry you are facing this issue, it would be my pleasure to help you.

Welcome to the Shopify community!😊
Thanks for your good question.

Please share your site URL,
I will check out the issue and provide you a solution here.

If helpful then please Like and Accept Solution. Partnership of your ️ Coffee Tips and my code can bring miracles.
Want to modify or custom changes on store Hire Me.
- Feel free to contact me on bamaniyaketan.sky@gmail.com regarding any help Shopify Partner | Skype : bamaniya.sky
PSD to Shopify | Shopify Design Changes | Shopify Custom Theme Development and Desing | Custom Modifications In to Shopify Theme | SEO & Digital Marketing
Nate_Dev
Shopify Partner
2 0 0

Change the max-blocks to have 4..

  "name": "Gallery",
  "max_blocks": 4,
  "settings": [

 This max block can be anything from 1-unlimited number. This will allow you to add more blocks in the customizer.

 

Nate

Mich-
Visitor
1 0 1

Hello, 

 

I am having the same problem — I would like to create an image gallery exactly as described in the original post. I tried to copy the code provided into a custom liquid section but I received a syntax error message. 

 

Has anyone got working code for an image gallery section, that when an image is clicked, it routes to the page for that specific product?

 

My store url is otherworldnotebooks.com

 

Would really appreciate any help! 

KetanKumar
Shopify Partner
37618 3670 12165

@Mich- 

sorry i can't see the gallery section on home page can you show me with issue details 

If helpful then please Like and Accept Solution. Partnership of your ️ Coffee Tips and my code can bring miracles.
Want to modify or custom changes on store Hire Me.
- Feel free to contact me on bamaniyaketan.sky@gmail.com regarding any help Shopify Partner | Skype : bamaniya.sky
PSD to Shopify | Shopify Design Changes | Shopify Custom Theme Development and Desing | Custom Modifications In to Shopify Theme | SEO & Digital Marketing

made4Uo
Shopify Partner
3875 719 1230

Hi, 

 

Add a masonry image gallery in your Shopify website. Work with Dawn and even the older themes.

If this fixed your issue Likes and Accept as Solution is highly appreciated. Coffee tips fuels my dedication.
Get EXPERIENCED Shopify developers at affordable rates—visit Made4Uo.com for quick quote!
Do not lost your Shopify store! Get FREE trial with ✔️ Rewind Backup: Automatic, reliable, stress-free
Kaspars_Rokjans
New Member
4 0 0

Hello!

 

I tried the code. Looks good but does not display the grid of the images in the theme.

Can you help?

ethnica
Tourist
6 1 2

Hi, it doesn't work, it doesn't show images in customize editing and in the code it shows an error: "missing width and height attributes"

KetanKumar
Shopify Partner
37618 3670 12165

@ethnica oh sorry for that issue 

can you please send your store url so i will check and let you know 

If helpful then please Like and Accept Solution. Partnership of your ️ Coffee Tips and my code can bring miracles.
Want to modify or custom changes on store Hire Me.
- Feel free to contact me on bamaniyaketan.sky@gmail.com regarding any help Shopify Partner | Skype : bamaniya.sky
PSD to Shopify | Shopify Design Changes | Shopify Custom Theme Development and Desing | Custom Modifications In to Shopify Theme | SEO & Digital Marketing