<p>You can add Breadcrumbs with the help of craft cms plugins like breadcrumbs and navigations as well they also work well for adding breadcrumbs</p>

CC BY-SA 4.0
2022-01-10T12:13:01.290Z
2022-01-10T12:13:01.290Z
DTS
<p>You will need some way to identify which category the user came from. You could use the referrer header or track the last category the user visited in a session variable, but both of those methods are error-prone and won't play nicely with caching. Instead, I'd include the category as a URL parameter and generate the breadcrumbs based on that. So on your category pages, add the current category as a parameter to the product links.</p>
<pre class="lang-twig prettyprint-override"><code>{% set productUrl = siteUrl(product.getUrl(), params = { from: category.id }) %}
</code></pre>
<p>So if category Brands -&gt; Adidas -&gt; Jacket has ID <code>123</code>, this will result in a link like this: <code>/products/some-jacket?from=123</code></p>
<p>Then you can use this parameter to diplay the breadcrumb trail for that category.</p>
<hr />
<p>A broader view: A breadcrumb navigation isn't a good fit for products with multiple categories. While the approach above will work, it might be confusing to the user. If I visit the same product twice, I might end up with two identical product pages with different breadcrumbs. Instead, I would display a list of categories the product belongs to, allowing the user to go back to the overview in any direction they want to.</p>

CC BY-SA 4.0
2022-01-07T13:34:21.260Z
2022-01-07T13:34:21.260Z
MoritzLost
<p>I have a question related to breadcrumbs. I have a multiple categories with level 3 hierarchy, now if I assign only one category to any product it works for me to create the breadcrumbs based on the category from where user reach to the product page. But when I select multiple categories then its not working for me as it shows the same breadcrumb no matter from which category user reach to the Product page.
Is there a way to change the breadcrumbs based on the category path from where a user reach to the product page?</p>
<p>for example:</p>
<pre><code>Shop
    Clothes
        ActiveWear
           Jacket
    Brands
        Adidas
           Jacket
</code></pre>
<p>So if user go from the Clothes category the breadcrumb must be Clothes-&gt;ActiveWear-&gt;Jacket
and if user go from the Brands category the breadcrumb must be Brands-&gt;Adidas-&gt;Jacket</p>
<p>Please let me know if there is a way. Thanks in advance.</p>

CC BY-SA 4.0
2022-01-07T14:09:57.500Z
Please consider rethinking your content model here. Smashing lots of different content types into a single hierarchical category structure severely reduces the flexibility and robustness of your site. Rather, aim to flatten the hierarchy into unique content types and create relationships between those types. In your example, you could have dedicated sections (or category groups) for "Product Types" and "Brands". Your Product Types category group would be fine to have a parent-child relationship from "Clothes > Jackets", as that makes sense ("Jackets" are a more specific type of "Clothes").
James Smith
CC BY-SA 4.0
2022-01-07T14:11:56.797Z
Don't allow the front-end display requirements to dictate the content modelling choices, as this harms the future-proofing of the site. For a more complete discussion of why this matters see here: https://cld.agency/blog/content-utopia
James Smith
CC BY-SA 4.0
2022-01-09T20:15:32.797Z
FYI breadcrumbs are intended to show a relationship between the current page and how the rest of the site is organized, usually it matches the global navigation. I would consider a brand to be more of a “filter” than “category” a product lives in. Typically you link to a manufacturer/brand from a product page anyway so including that path isn’t really useful from a buyer perspective. Ultimately  [breadcrumbs are not intended](https://www.nngroup.com/articles/breadcrumbs/) to show the trail a user took, like Hansel and Gretel (see point #2).
RitterKnight
<categories>
What is the best way to create breadcrumbs based on a categories?
# What is the best way to create breadcrumbs based on a categories?

(Asked by: username_0 on 2022-01-07)

I have a question related to breadcrumbs. I have a multiple categories with level 3 hierarchy, now if I assign only one category to any product it works for me to create the breadcrumbs based on the category from where user reach to the product page. But when I select multiple categories then its not working for me as it shows the same breadcrumb no matter from which category user reach to the Product page.
Is there a way to change the breadcrumbs based on the category path from where a user reach to the product page?
for example:
Shop
    Clothes
        ActiveWear
           Jacket
    Brands
        Adidas
           Jacket

So if user go from the Clothes category the breadcrumb must be Clothes->ActiveWear->Jacket
and if user go from the Brands category the breadcrumb must be Brands->Adidas->Jacket
Please let me know if there is a way. Thanks in advance.

**Tags:** categories

> **Comments:**
> **username_1**: Please consider rethinking your content model here. Smashing lots of different content types into a single hierarchical category structure severely reduces the flexibility and robustness of your site. Rather, aim to flatten the hierarchy into unique content types and create relationships between those types. In your example, you could have dedicated sections (or category groups) for "Product Types" and "Brands". Your Product Types category group would be fine to have a parent-child relationship from "Clothes > Jackets", as that makes sense ("Jackets" are a more specific type of "Clothes").  
> **username_1**: Don't allow the front-end display requirements to dictate the content modelling choices, as this harms the future-proofing of the site. For a more complete discussion of why this matters see here: https://cld.agency/blog/content-utopia  
> **username_2**: FYI breadcrumbs are intended to show a relationship between the current page and how the rest of the site is organized, usually it matches the global navigation. I would consider a brand to be more of a “filter” than “category” a product lives in. Typically you link to a manufacturer/brand from a product page anyway so including that path isn’t really useful from a buyer perspective. Ultimately  [breadcrumbs are not intended](https://www.nngroup.com/articles/breadcrumbs/) to show the trail a user took, like Hansel and Gretel (see point #2).  

---

## 2 answers

### Answer by username_3 on 2022-01-10. Score: 1

You can add Breadcrumbs with the help of craft cms plugins like breadcrumbs and navigations as well they also work well for adding breadcrumbs


---

### Answer by username_4 on 2022-01-07. Score: 0

You will need some way to identify which category the user came from. You could use the referrer header or track the last category the user visited in a session variable, but both of those methods are error-prone and won't play nicely with caching. Instead, I'd include the category as a URL parameter and generate the breadcrumbs based on that. So on your category pages, add the current category as a parameter to the product links.
{% set productUrl = siteUrl(product.getUrl(), params = { from: category.id }) %}

So if category Brands -> Adidas -> Jacket has ID 123, this will result in a link like this: /products/some-jacket?from=123
Then you can use this parameter to diplay the breadcrumb trail for that category.

A broader view: A breadcrumb navigation isn't a good fit for products with multiple categories. While the approach above will work, it might be confusing to the user. If I visit the same product twice, I might end up with two identical product pages with different breadcrumbs. Instead, I would display a list of categories the product belongs to, allowing the user to go back to the overview in any direction they want to.


---

