Collections not showing in breadcrumbs

Highlighted
Tourist
7 0 2

Hi! 

I would like my product pages to show home - collection - product in the breadcrumbs but I'm only getting home - product. 

 

A while ago I changed the product pages so the url would not have the collection in the string. I think this may be the cause of the problem...but I can't remember how I did this. I want to keep the urls reading the same way. 

 

https://thelittlepotcompany.co.uk

 

My products are assigned to collections but it seems the breadcrumb code isn't able to read this? 

 

 
  <a href="/" title="{{ 'general.breadcrumbs.home_link_title' | t }}">{{ 'general.breadcrumbs.home' | t }}</a>

  {% if template.name == 'product' %}

    {% if collection %} 
      <span aria-hidden="true" class="breadcrumb__sep">&rsaquo;</span>
      {% if collection.handle %} 
        {% capture url %}/collections/{{ collection.handle }}{% endcapture %}
        {{ collection.title | link_to: url }}
  
      {% endif %}
  
    {% endif %}
   
    <span aria-hidden="true" class="breadcrumb__sep">&rsaquo;</span>
    <span>{{ product.title }} </span>

 

 

0 Likes
Highlighted
Tourist
7 0 2

This is how I worked out how to do it. I guess there must be a more elegant way?

 

  {% for collection in product.collections %}
 {% if collection.title != "Home page" %}
        <span aria-hidden="true" class="breadcrumb__sep">&rsaquo;</span>
  <a href="{{ collection.url }}" title=" {{ collection.title }}""> {{ collection.title }}</a>
  {% endif %}                                                             
{% endfor %}
0 Likes
Highlighted
New Member
2 0 0

Hi Tom,

Do you mean replace the whole original code by the last one you posted or just some specific lines?

 

Thanks

0 Likes