Link to collection

Tourist
46 0 1

Hi all,

How do i put a link on a product page that goes to the collection that product is in. So a customer can click on text that says "see the rest of this collection" and it brings up the collection page that the product belongs to.

I know this is easy to do in the product description area but I don't want it there as mobile users often don't scroll down.

I would like the link to appear near the product title, but I can't figure out the liquid code for it.

 

0 Likes

Hello 

 

For adding collection link you need to go to section>product-template> and search for product.title and add this code

{% if collection %}
          <div>
            <a href="{{ collection.url }}">
               see the rest of this collection
            </a>
          </div>
        {% endif %}

Thank you!

Want to modify or custom changes on store hire me.
If helpful then please Like and Accept Solution.
Email: codecorneres@gmail.com
Skype: code.corners
0 Likes
Tourist
46 0 1

Thanks for replying.

That works fine when a product is clicked on from a collection page.

But when a customer goes directly to the product page (ie. from a search engine like most of my customers), it doesn't display anything.

 

0 Likes

Yes collection show only when customer comes from collections page if you want to show collection when customer comes directly to the product page then the issue is we need to show first collection if product have more than one collections.so we need to modify code for that

Want to modify or custom changes on store hire me.
If helpful then please Like and Accept Solution.
Email: codecorneres@gmail.com
Skype: code.corners
0 Likes

Hello 

Online Store-> Themes -> Edit code->Sections->product-template.liquid

You can add code below this line

<h2 itemprop="name">{{ product.title }}</h2>
 <a href="javascript&colon;history.go(-1)">see the rest of this collection</a> 

This code will work if you go through collection.

Want to modify or incorporate custom changes on store, Hire us.
If helpful then please Like and Accept Solution .
Email: pallavi@oscprofessionals.com
Skype : oscprofessionals-87
Custom Shopify Private App | Custom Theme Development | Custom Modifications In To Shopify Theme | Digital Marketing | Site Speed Optimization | Web Development
0 Likes
Tourist
46 0 1

@CodeCorners wrote:

Yes collection show only when customer comes from collections page if you want to show collection when customer comes directly to the product page then the issue is we need to show first collection if product have more than one collections.so we need to modify code for that


Thanks. Do you know the code needed to do that?

0 Likes

okay replace this code by previous code and let me know if that works or not: 

{% if collection %}
          <div>
            <a href="{{ collection.url }}">
               see the rest of this collection
            </a>
          </div>
        {%else%}
         <div>
            <a href="{{ product.collections.first.url }}">
               see the rest of this collection
            </a>
          </div>
        {% endif %}

Thanks

Want to modify or custom changes on store hire me.
If helpful then please Like and Accept Solution.
Email: codecorneres@gmail.com
Skype: code.corners
0 Likes
Highlighted
Tourist
46 0 1

@CodeCorners wrote:

okay replace this code by previous code and let me know if that works or not: 


Yes thank you, that seems to work fine.

One last thing, do you know how to include the name of the collection in the link, so that the link text says "see the rest of our Nike collection" (for example).

I tried "see the rest of our {{ product.collections.title }} collection"  (which I just guessed at) but it didn't work.

0 Likes