Skip to content

Instantly share code, notes, and snippets.

@levinmejia
Created October 21, 2015 17:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save levinmejia/037d9818dd68fc95f2e9 to your computer and use it in GitHub Desktop.
Save levinmejia/037d9818dd68fc95f2e9 to your computer and use it in GitHub Desktop.
<ul class="block-grid mobile four-up product-collection">
{% for link in linklist.links %}
<li>
<div class="product">
{% comment %}
You can connect collections, products, pages, & even blogs. By default it will use the first product that appears on a collection or you can pick a featured image as we’ve done.
{% endcomment %}
{% assign link_item = link.object %}
{% assign link_image = '' %}
{% capture link_title %}{{ link.title | escape }}{% endcapture %}
{% if link.type == 'collection_link' %}
{% if link_item.image %}
{% assign link_image = link_item.image.src | collection_img_url: 'medium' %}
{% else %}
{% assign link_image = link_item.products.first.featured_image | product_img_url: 'medium' %}
{% endif %}
{% elsif link.type == 'product_link' %}
{% assign link_image = link_item.featured_image | product_img_url: 'medium' %}
{% elsif link.type == 'page_link' %}
{% if link_item.content contains "<img" %}
{% assign src = link_item.content | split: 'src="' %}
{% assign src = src[1] | split: '"' | first | replace: '//cdn', 'http://cdn' | replace: 'http:http://', 'http://' | remove: 'https:' %}
{% if src %}
{% assign link_image = src %}
{% endif %}
{% endif %}
{% elsif link.type == 'blog_link' %}
{% if link_item.articles.first.content contains "<img" %}
{% assign src = link_item.articles.first.content | split: 'src="' %}
{% assign src = src[1] | split: '"' | first | replace: '//cdn', 'http://cdn' | replace: 'http:http://', 'http://' | remove: 'https:' %}
{% if src %}
{% assign link_image = src %}
{% endif %}
{% endif %}
{% endif %}
<a href="{{ link_item.url }}" title="{{ link_title }}">
<span class="thumbnail">
{% if link_image != '' %}
<img {% if settings.align_height %}style="max-height:{{ settings.collection_height }}px"{% endif %} src="{{ link_image }}" alt="{{ link_title }}" />
{% endif %}
</span>
<span class="product-title">
{{ link_title }}
</span>
</a>
</div>
</li>
{% endfor %}
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment