Related Products not showing correctly - html

I am trying to generate related products in one of my shopify store, its showing on some products but mostly not, what I want is, display related product first by matching vendor/brand, if not found then show the products of same category:
Can anybody please suggest how to handle this?
<div class="related-products row">
{% assign vendor = product.vendor %}
{% assign vendor_handle = vendor | handleize %}
{% assign handle = product.handle %}
<h4 style="text-align:left;">More in this collection</h4>
{% assign counter = '' %}
{% for product in collections[vendor_handle].all_products %}
{% if vendor == product.vendor and counter.size < 4 and handle != product.handle %}
{% capture temp %}{{ counter }}*{% endcapture %}
{% assign counter = temp %}
<div class="col-md-3 col-sm-3 col-xs-12">
<div class="reveal">
<a href="{{ product.url | within: collection }}" title="{{ product.title }}">
<img src="{{ product.images.first | product_img_url: 'large' }}" class="img-responsive" alt="{{ product.title }}" />
</a>
</div>
<a href="{{ prod.url | within: collection }}" title="{{ prod.title | escape }}">
{{ product.title | escape }}
</a>
</div>
{% endif %}
{% endfor %}
</div>

You're changing the main product by using the following line
{% for product in collections[vendor_handle].all_products %}
and what is prod?
Try the following
<div class="related-products row">
{% assign vendor = product.vendor %}
{% assign vendor_handle = vendor | handleize %}
{% assign handle = product.handle %}
<h4 style="text-align:left;">More in this collection</h4>
{% assign counter = 0 %}
{% for coll_product in collections[vendor_handle].all_products %}
{% if vendor == coll_product.vendor and counter < 4 and handle != coll_product.handle %}
{% assign counter = counter | plus: 1 %}
<div class="col-md-3 col-sm-3 col-xs-12">
<div class="reveal">
<a href="{{ coll_product.url | within: collection }}" title="{{ product.title }}">
<img src="{{ coll_product.images.first | product_img_url: 'large' }}" class="img-responsive" alt="{{ coll_product.title }}" />
</a>
</div>
<a href="{{ coll_product.url | within: collection }}" title="{{ coll_product.title | escape }}">
{{ coll_product.title | escape }}
</a>
</div>
{% endif %}
{% endfor %}
</div>

Related

How to add an active class with if statement in Liquid (Shopify)

I have 2 links inside the header (one link takes you to one stores the other link takes you to another store). I need to add an active class to the store the user is on (bmx-store & skate-store are the 2 classes that need active class adding to). So if the user is on the bmx store, the link for that store becomes bold and underlined and vice versa.
{% if request.url contains 'source-bmx-testing.myshopify.com' %}
{% elsif request.url contains 'sourceskate.myshopify.com' %}
{% endif %}
I know the code needs to be similar to the snippet above but not sure how to add it into the code i have to add the active class to the store depending on which one you are on. Below is my code:
{%- for block in section.blocks -%}
{%- case block.type -%}
{%- when 'bmx-link' -%}
<a class="link-container" href="{{ block.settings.store_link }}">
<div class="bmx-store">
<img
width="15"
height="15"
src="{{ block.settings.icon_image | img_url: '15x15' }}"
srcset="{{ block.settings.icon_image | img_url: '15x15' }}"
alt="{{ block.settings.icon_image.alt }}">
<span>{{ block.settings.store_link_title }}</span>
</div>
</a>
{%- when 'skate-link' -%}
<a class="link-container" href="{{ block.settings.store_link }}">
<div class="skate-store">
<img
width="15"
height="15"
src="{{ block.settings.icon_image | img_url: '15x15' }}"
srcset="{{ block.settings.icon_image | img_url: '15x15' }}"
alt="{{ block.settings.icon_image.alt }}">
<span>{{ block.settings.store_link_title }}</span>
</div>
</a>
{%- endcase -%}
{%- endfor -%}
{% assign bmx_class = 'bmx-store' %}
{% assign skate_class = 'skate-store' %}
{% if shop.name == 'bmx' %} <!-- use youre store name here -->
{% assign bmx_class = 'bmx-store current-store' %}
{% elsif shop.name == 'skate' %}
{% assign skate_class = 'skate-store current-store %}
{% endif %}
{%- for block in section.blocks -%}
{%- case block.type -%}
{%- when 'bmx-link' -%}
{% assign class_block = bmx_class %}
{%- when 'skate-link' -%}
{% assign class_block = skate_class %}
{% endcase %}
<a class="link-container" href="{{ block.settings.store_link }}">
<div class="{{ class_block }}">
<img
width="15"
height="15"
src="{{ block.settings.icon_image | img_url: '15x15' }}"
srcset="{{ block.settings.icon_image | img_url: '15x15' }}"
alt="{{ block.settings.icon_image.alt }}">
<span>{{ block.settings.store_link_title }}</span>
</div>
</a>
{%- endfor -%}
If stores are more than 2 other cleaner solutions can be found.

Item.Image not displaying in Jekyll

I have a bunch of portfolio posts in /_works/ and the front matter looks something like this:
title: "Rock in Rio Lisbon 2018"
date: July, 2018
image: "/assets/images/work/rock-in-rio-lisbon-2018.jpg"
categories:
- Intro
slides:
- title: "Rock in Rio Lisbon 2018 Headliner Show for Bruno Mars, Katy Perry, Muse & The Killers"
id: "O-rZ6IFnv9g"
override: true
On the homepage I'm using the Slides.ID to automatically grab the YouTube video's thumbnail. If the front matter includes Override: true it should display what I have defined as the image instead. Here is the what I have:
{% assign works = site.works | reverse %}
{% for item in works limit:9 %}
<li class="{% cycle 'wide','','','','','','','','' %}">
<a href='{{ site.url }}{{ item.url }}'>
{% if item.override %}
{% for item in item.slides limit:1 %}
<img alt="A frame from a video of {{ item.title }}" loading="lazy" src="{{ site.url }}{{ item.image }}" />
{% endfor %}
{% else %}
{% for item in item.slides limit:1 %}
<img alt="A frame from a video of {{ item.title }}" loading="lazy" src="https://img.youtube.com/vi/{{ item.id }}/sddefault.jpg" />
{% endfor %}
{% endif %}
<div class='overlay'>
<div class='thumb-info'>
<h3>{{ item.title }}</h3>
<p>{{ item.categories | sort | join:" • " | escape }}</p>
<p>{{ item.image }}</p>
</div>
</div>
</a>
</li>
{% endfor %}
When Jekyll compiles, the {{ item.image }} is not working…however, if I swap it with {{ item.title }} it does work. Any ideas why this is happening?
You are reusing the 'item' variable in slides, which overwrites it. Rename the variable 'item' to 'slide' when you are looping through the slides, like this:
{% assign works = site.works | reverse %}
{% for item in works limit:9 %}
<li class="{% cycle 'wide','','','','','','','','' %}">
<a href='{{ site.url }}{{ item.url }}'>
{% if item.override %}
{% for slide in item.slides limit:1 %}
<img alt="A frame from a video of {{ slide.title }}" loading="lazy" src="{{ site.url }}{{ slide.image }}" />
{% endfor %}
{% else %}
{% for slide in item.slides limit:1 %}
<img alt="A frame from a video of {{ slide.title }}" loading="lazy" src="https://img.youtube.com/vi/{{ slide.id }}/sddefault.jpg" />
{% endfor %}
{% endif %}
<div class='overlay'>
<div class='thumb-info'>
<h3>{{ item.title }}</h3>
<p>{{ item.categories | sort | join:" • " | escape }}</p>
<p>{{ item.image }}</p>
</div>
</div>
</a>
</li>
{% endfor %}

Shopify Footer Grid - Size and Align Content

I'm working on my Shopify using the Brooklyn theme. I need help with my footer adjustments. I can't seem to get the footer to be shorter in height. There's so much empty space in there. In the attached photo, you can see I have two columnns. The one on the left has two piece of content and the one on the right has one. How can I push all three of these out to the edge? I tried to set the padding and margins to 0...but it doesn't work. I want it closer to the outside rather than leaving a big space on both sides.
Thank you!
Footer Image
<footer class="site-footer small--text-left" role="contentinfo">
<div class="grid">
{% comment %}
Default to 1 footer column (copyright/powered_by/payment_types)
{% endcomment %}
{% comment %} Added by Ludo S on July 16 2018 {% endcomment %}
{% if section.settings.footer_newsletter_enable %}
{% assign num_footer_columns = 0 %}
{% else %}
{% assign num_footer_columns = 1 %}
{% endif %}
{% if section.settings.footer_newsletter_enable %}
{% assign num_footer_columns = num_footer_columns | plus: 1 %}
{% endif %}
{% comment %}
Create an extra menu column if link list has more than 5 links
{% endcomment %}
{% if linklists[section.settings.footer_link_list].links.size > 0 %}
{% comment %}
We have a Footer menu that isn't empty, we will need another column
{% endcomment %}
{% assign num_footer_columns = num_footer_columns | plus: 1 %}
{% assign extra_footer_linklist_column = false %}
{% assign footer_linklist_count = linklists[section.settings.footer_link_list].links.size %}
{% if footer_linklist_count > 5 %}
{% assign extra_footer_linklist_column = true %}
{% comment %}
We split the links so we'll need another column
{% endcomment %}
{% assign num_footer_columns = num_footer_columns | plus: 1 %}
{% endif %}
{% comment %}
If we have an odd amount of links, we need to show 1 more link in 1st column
{% endcomment %}
{% assign extra_link = footer_linklist_count | modulo: 2 %}
{% comment %}
We start with a 2nd column after first column is filled up.
{% endcomment %}
{% assign footer_linklist_split = footer_linklist_count | divided_by: 2 | plus: extra_link | plus: 1 %}
{% endif %}
{% comment %}
Determine whether there are social links
{% endcomment %}
{% assign footer_social_enable = false %}
{% if
settings.social_twitter_link != blank
or settings.social_facebook_link != blank
or settings.social_pinterest_link != blank
or settings.social_google_plus_link != blank
or settings.social_instagram_link != blank
or settings.social_tumblr_link != blank
or settings.social_youtube_link != blank
or settings.social_vimeo_link != blank
or settings.social_fancy_link != blank
or settings.social_snapchat_link != blank
%}
{% assign footer_social_enable = true %}
{% endif %}
{% comment %}
Calculate the number of footer columns shown. Default to 1.
{% endcomment %}
{% if footer_social_enable %}
{% assign num_footer_columns = num_footer_columns | plus: 1 %}
{% endif %}
{% case num_footer_columns %}
{% when 0 %}
{% when 1 %}
{% assign footer_column_width = '' %}
{% when 2 %}
{% assign footer_column_width = 'one-half small--one-whole' %}
{% when 3 %}
{% assign footer_column_width = 'one-third small--one-whole' %}
{% when 4 %}
{% assign footer_column_width = 'large--one-quarter medium--one-half' %}
{% endcase %}
{% if linklists[section.settings.footer_link_list].links.size > 0 %}
<div class="grid grid__item {% if num_footer_columns == 1 %} one-half push--large--one-quarter push--medium--one-quarter small--one-whole{% else %} {{ footer_column_width }}{% endif %}">
<ul class="no-bullets site-footer__linklist">
{% for link in linklists[section.settings.footer_link_list].links %}
{% comment %}
Create a second column
{% endcomment %}
{% if extra_footer_linklist_column and forloop.index == footer_linklist_split %}
</ul>
</div>
<div class="grid grid__item {% if num_footer_columns == 1 %} one-half push--large--one-quarter push--medium--one-quarter small--one-whole{% else %} {{ footer_column_width }}{% endif %}">
<ul class="no-bullets site-footer__linklist">
{% endif %}
<li>{{ link.title }}</li>
{% endfor %}
</ul>
</div>
{% endif %}
{% if footer_social_enable %}
{% comment %} Added the if statement for the class and made the div a grid item by Ludo S on July 16 2018 {% endcomment %}
<div class="grid grid__item {% if num_footer_columns == 1 %} one-half push--large--one-quarter push--medium--one-quarter small--one-whole{% else %} {{ footer_column_width }}{% endif %}">
<ul class="no-bullets social-icons">
{% if settings.social_instagram_link != blank %}
<li>
<a href="{{ settings.social_instagram_link | escape }}" title="{{ 'layout.footer.social_platform' | t: name: shop.name, platform: 'Instagram' }}">
<span class="icon icon-instagram" aria-hidden="true"></span>
Instagram
</a>
</li>
{% endif %}
{% if settings.social_facebook_link != blank %}
<li>
<a href="{{ settings.social_facebook_link | escape }}" title="{{ 'layout.footer.social_platform' | t: name: shop.name, platform: 'Facebook' }}">
<span class="icon icon-facebook" aria-hidden="true"></span>
Facebook
</a>
</li>
{% endif %}
{% if settings.social_twitter_link != blank %}
<li>
<a href="{{ settings.social_twitter_link | escape }}" title="{{ 'layout.footer.social_platform' | t: name: shop.name, platform: 'Twitter' }}">
<span class="icon icon-twitter" aria-hidden="true"></span>
Twitter
</a>
</li>
{% endif %}
{% if settings.social_pinterest_link != blank %}
<li>
<a href="{{ settings.social_pinterest_link | escape }}" title="{{ 'layout.footer.social_platform' | t: name: shop.name, platform: 'Pinterest' }}">
<span class="icon icon-pinterest" aria-hidden="true"></span>
Pinterest
</a>
</li>
{% endif %}
{% if settings.social_snapchat_link != blank %}
<li>
<a href="{{ settings.social_snapchat_link | escape }}" title="{{ 'layout.footer.social_platform' | t: name: shop.name, platform: 'Snapchat' }}">
<span class="icon icon-snapchat" aria-hidden="true"></span>
Snapchat
</a>
</li>
{% endif %}
{% if settings.social_google_plus_link != blank %}
<li>
<a href="{{ settings.social_google_plus_link | escape }}" rel="publisher" title="{{ 'layout.footer.social_platform' | t: name: shop.name, platform: 'Google Plus' }}">
<span class="icon icon-google_plus" aria-hidden="true"></span>
Google Plus
</a>
</li>
{% endif %}
{% if settings.social_tumblr_link != blank %}
<li>
<a href="{{ settings.social_tumblr_link | escape }}" title="{{ 'layout.footer.social_platform' | t: name: shop.name, platform: 'Tumblr' }}">
<span class="icon icon-tumblr" aria-hidden="true"></span>
Tumblr
</a>
</li>
{% endif %}
{% if settings.social_youtube_link != blank %}
<li>
<a href="{{ settings.social_youtube_link | escape }}" title="{{ 'layout.footer.social_platform' | t: name: shop.name, platform: 'YouTube' }}">
<span class="icon icon-youtube" aria-hidden="true"></span>
YouTube
</a>
</li>
{% endif %}
{% if settings.social_vimeo_link != blank %}
<li>
<a href="{{ settings.social_vimeo_link | escape }}" title="{{ 'layout.footer.social_platform' | t: name: shop.name, platform: 'Vimeo' }}">
<span class="icon icon-vimeo" aria-hidden="true"></span>
Vimeo
</a>
</li>
{% endif %}
{% if settings.social_fancy_link != blank %}
<li>
<a href="{{ settings.social_fancy_link | escape }}" title="{{ 'layout.footer.social_platform' | t: name: shop.name, platform: 'Fancy' }}">
<span class="icon icon-fancy" aria-hidden="true"></span>
Fancy
</a>
</li>
{% endif %}
</ul>
</div>
{% endif %}
{% comment %} Added by Ludo S on July 16 2018 {% endcomment %}
{% if section.settings.footer_newsletter_enable %}
<div class="customNewsletter grid__item{% if num_footer_columns == 1 %} one-half push--large--one-quarter push--medium--one-quarter small--one-whole{% else %} {{ footer_column_width }}{% endif %}{% if num_footer_columns == 4 %} narrow-newsletter{% endif %}">
{% form 'customer' %}
{{ form.errors | default_errors }}
{% if form.posted_successfully? %}
<div class="newsletter--form">
<div class="note form-success">{{ 'general.newsletter_form.newsletter_confirmation' | t }}</div>
</div>
{% else %}
<label for="Email" class="newsletter__label hidden-label">{{ 'general.newsletter_form.newsletter_email' | t }}</label>
<input type="hidden" name="contact[tags]" value="newsletter">
<div class="newsletter--form">
<p class="h2" style="color:{{ section.settings.newsletter_text_color }}">Stay in touch!</p><br>
<p class="h6" style="color:{{ section.settings.newsletter_text_color }}">Get updates on our newest styles.</p>
<div class="input-group">
<input type="email" value="{% if customer %}{{ customer.email }}{% endif %}" placeholder="{{ 'general.newsletter_form.newsletter_email' | t }}" name="contact[email]" id="Email" class="input-group-field newsletter__input" autocorrect="off" autocapitalize="off">
<span class="input-group-btn">
<button type="submit" class="btn newsletter__submit" name="commit" id="Subscribe">
<span class="newsletter__submit-text--large">{{ 'general.newsletter_form.submit' | t }}</span>
<span class="newsletter__submit-text--small">
<span class="icon icon-arrow-right" aria-hidden="true"></span>
</span>
</button>
</span>
</div>
</div>
{% endif %}
{% endform %}
</div>
{% endif %}
<div class="grid grid__item one-half push--large--one-quarter push--medium--one-quarter small--one-whole">
<p style="color:white">© {{ 'now' | date: '%Y' }}, {{ shop.name | link_to: '/' }}<br>Powered by Caffeine + Doggie Kisses</p></p>
{%- if section.settings.show_payment_icons -%}
{%- unless shop.enabled_payment_types == empty -%}
<span class="visually-hidden">{{ 'general.payment.method' | t }}</span>
<ul class="inline-list payment-icons">
{%- for type in shop.enabled_payment_types -%}
<li>
{{ type | payment_type_svg_tag: class: 'icon' }}
</li>
{%- endfor -%}
</ul>
{%- endunless -%}
{%- endif -%}
</div>
</div>

Shopify changing the layout of the collections

I would like to change the layout of a page of collections, right now it's just one column. I would like to make it at least 3 per row.
Here is the existing layout
to something like this
1:
Here's the code
<div id="content" class="col-md-12 center-column content-with-background">
<div class="row">
<div class="col-sm-12">
{{page.content}}
</div>
</div>
</div>
{% comment %}
Collections are listed here.
{% endcomment %}
{% capture uses_minimal_framework %}{% include 'product-loop' %}{% endcapture %}
{% if uses_minimal_framework contains 'Liquid error' %}
{% assign uses_minimal_framework = false %}
{% assign grid_item_width = 'large--one-quarter medium--one-third small--one-half large--col-3 medium--col-4 small--col-6' %}
{% else %}
{% assign uses_minimal_framework = true %}
{% assign grid_item_width = 'span3' %}
{% endif %}
{% assign image_size = 'medium' %}
{% if linklists[page.handle].links.size > 0 %}
{% assign number_of_links = 0 %}
<div class="grid-uniform{% if uses_minimal_framework %} row{% endif %} clearfix">
{% for link in linklists[page.handle].links %}
{% if link.type == 'collection_link' %}
{% comment %}
If we have a collection link.
{% endcomment %}
{% assign collection = link.object %}
{% assign number_of_links = number_of_links | plus: 1 %}
<div class="grid__item grid-item product-grid-item {{ grid_item_width }} text-center">
<div class="grid__image product-grid-image">
<a href="{{ link.url }}" class="grid-image--centered">
{% comment %}
Bring in the featured image of the first product in the collection if no collection
image has been uploaded for it.
{% endcomment %}
{% if collection.image %}
<img src="{{ collection | img_url: image_size }}" alt="{{ link.title | escape }}">
{% else %}
{% assign product = collection.products.first %}
<img src="{{ product | img_url: image_size }}" alt="{{ link.title | escape }}">
{% endif %}
</a>
</div>
<p class="collection-grid__item-title">
{{ link.title }}
</p>
</div>
{% if uses_minimal_framework %}
{% cycle 'clear-item': '', '', '', '<div style="clear:both"></div>' %}
{% endif %}
{% elsif link.type == 'page_link' %}
I don't know where to edit the code so i copied the part i think it is in. Thank you so much.
Try changing the 3rd line
<div class="col-sm-12">
to this
<div class="col-md-12">
That should resize it to fit more items on the screen.

Shopify After 4 Products add a Horizontal Break

I'm trying to figure out how to add a horizontal break after 4 products within the Shopify product loop. Is this possible at all? I've looked through their documentation but it doesn't show the possibility of counting or iterating over the loop.
Currently my loop looks as follows:
{% if collection.all_products_count > 0 %}
<div class="w-col w-col-12">
<div class="product-feed w-clearfix">
{% for product in collection.products %}
<a class="product product-collection w-inline-block" href="{{ product.url | within:collection }}">
<div class="reveal">
<img src="{{ product.featured_image | product_img_url: 'original' }}" alt="{{ product.title | escape }}" class="product-photo">
<img src="{{ product.images.last | product_img_url: 'original' }}" alt="{{ product.title | escape }}" class="hidden">
</div>
<h3 class="product-title">{{ product.title }}</h3>
<div class="product-price">{{ product.price | money }}</div>
<span class="shopify-product-reviews-badge" data-id="{{ product.id }}"></span>
</a>
{% endfor %}
</div>
{% assign count = paginate.pages %}
{% for part in (1..count) %}
<li {% if paginate.current_page == part %}class="active"{% endif %}>{{ forloop.index }}</li>
{% endfor %}
{% else %}
<p>Sorry, there are no products in this collection</p>
{% endif %}
It's fair explanation that you have not gone through the documentation properly. Refer this: - https://help.shopify.com/themes/liquid/objects/for-loops
Straight forward way to get this to work is add the following line before {% endfor %}
{% cycle '','','','<hr>' %} // or <br> if you prefer
<hr> gets added every time the forloop is iterating the 4th time. More on this - https://help.shopify.com/themes/liquid/tags/iteration-tags#cycle