How can I integrate pagination to index.liquid page using the configured collection?
{% assign collection = collections.collectionName %}
{% paginate collection.products by settings.pagination_limit %}
...
So instead of collectionName I want to use the collection from theme settings (Themes / Home / Collection of products).
Is it possible?
And I just found it. If anybody has a same problem:
{% assign collection = collections[settings.frontpage_collection] %}
Related
I have create many collections like All Products, New Releases, T-Shirts, Pants etc. And I have two categories of products like Men's and Women's. Some collections specifically for Men's and some collections specifically for Women's. I create two tags Men's and Women's. I create menu by collections query by tags. My my products collection url is like this:
/collections/all-products/mens
/collections/all-products/womens
/collections/new-releases/mens
/collections/new-releases/womens
/collections/bras/womens
I want to show some text and menu list when collection.url show /mens or /womens.
{% if collection.url contains mens %}
do something
{% endif %
Above condition not working. I know why not working because {{ collection.url }} provide /collections/all-products. {{ page.url }} will not work for collection object. I haven't find any suggestion or liquid code reference where show men's or women's products in collections page it will show specific text.
If use in loop it will work.
{% for product in collection.products %}
{% for tag in product.tags %}
{% if tag contains 'mens' %}
<h3>Mens Products</h3>
{% endif %}
{% endfor %}
{% endfor %}
Above code will not work for me because it's inside loop. I need to show outside of loop. I don't understand how to achieve it. here is the reference site. Below have image how I want.
Need help!
You have access to the current_tags, refer to docs: https://shopify.dev/docs/themes/liquid/reference/objects/current-tags
This will return an array of all the tags you are viewing at the moment (in case you are viewing more than one tag).
So your check will be:
{% if current_tags contains 'mens' %}
do something
{% endif %}
That's pretty much the just of it.
I really like how the menu is coming along! Here are some ideas you could consider for your category specific menu, if you've not gotten where you want yet.
For your url strategy, what you're looking for is handle. Handles are specific to liquid. https://shopify.dev/docs/themes/liquid/reference/basics/handle
You could make a custom collection template if those 2 categories need to be fairly different: https://shopify.dev/tutorials/customize-theme-create-alternate-templates. If you do that, then you can use template_prefix from the collection object.
Assign a variable outside your loop and then set it inside the loop like:
{% assign is_mens = false %}
{% for tag in product.tags %}
{% if tag contains 'mens' %}
{% assign is_mens = true %}
{% endif %}
{% endfor %}
then {% if is_mens %} or {% unless is_mens %} for your dynamic content, or a case statement to define content specific to categories in your menu.
Hope this helps!
Just wondering why this is not populating products in the Shopify page template but it's working normally in the article template:
{%- assign firstsecthandle = page.metafields.first-sect.rev-handle -%}
{% for product in collections[ firstsecthandle ].products %}
...
{% endfor %}
As a result of this, I get the list of collections instead of products on page template but on the article template I get products.
On the page template it works only if I put the exact URL handle of collection:
But I need collection-handle to be dynamically declared not to have static value.
A variant which is working with a static 'collection-handle':
{% for product in collections.collection-handle.products %}
...
{% endfor %}
How can I hide a product when it is unavailable? I am really close to figuring this out but my current problem is the pagination. Its saying there are 28 results.. when there should be 24 (4 products are sold out).
Here's what I have in my collection template..
{% assign number = section.settings.products_per_page %}
{% paginate collection.products by number %}
{% for product in collection.products %}
{% if product.available %}
{% include 'product-listing' %}
{% endif %}
{% endfor %}
{% include 'pagination' %}
{% endpaginate %}
Sadly you can't modify the pagination in any way. If for example you have a full page with sold out products no products will be shown.
The only way to modify this is to create a separate "smart collection" that will take products with bigger inventory stock than 0 and loop that one instead of the current one.
Solution 1. Use your own pagination.
You can use your own pagination. It is really easy. If you have this structure:
<ul>
{% for product in collection.products %}
<li {% if forloop.index > 8 %}style="display: none;"{% endif %}>product</li>
{% endfor %}
</ul>
<a class="showmore">show more</a>
... you can use this jQuery:
$(".showmore").click(function() {
for (i = 0; i < 8; i++) {
if($(this).prev().find('li:hidden').length==0) $(this).remove();
$(this).prev().find('li:hidden').first().css('display','block');
}
});
Note that in a large store you might want to put the 'src' attribute of images in a 'data-src' attribute and replace them on toggle/show. This prevents all images being loaded at once in the overview.
Solution 2. Not hiding, but marking.
You could also show SOLD OUT next to your product, instead of hiding it. This is the easiest solution by far.
Hello Shopify Developers.
I'm a newbie on Shopify. I want to build a menu just like http://www.nastygal.com/. It shows menu items and featured products in menu area.
Would you give me a suggestion how to make a menu like this?
I'm not sure this is the best idea, though I think that I can create special collections to assign menus. I want to add a custom field in collection page to assign category to special menu. I noticed that I may use meta-fields for this but not sure.
How to add meta-fields to description fields in collection admin page?
How to get values from meta-fields in front page?
I'm open for suggestions, please teach me.
Best regards, Lorant.
I'd say there was a couple of steps to making this work, but it shouldn't be hard.
Create a collection that contains the products in it that you would like to show in the menu.
In your navigation link list create a link that points to collection you want to show in the menu. Call it something like show-products.
The menu liquid would look something like this:
{% assign linklist = linklists.main-menu %}
{% for link in linklist %}
{% if link.title == 'show-products' and link.type == 'collection_link' %}
{% assign menu_collection = link.object %}
{% for menu_product in menu_collection.products %}
{{ menu_product.featured_image | product_img_url: 'compact' | img_tag: menu_product.title }}
{{ menu_product.title }}
{% endfor %}
{% else %}
{% include 'my-normal-menu-link' with link %}
{% endif %}
{% endfor %}
Note: this code is untested, but I don't see why it wouldn't work.
I'm trying to retrieve all Shopify collections for our store which have products matching tag dog.
{% for collection in collections %}
{% assign gato = 'false' %}
{% assign perro = 'false' %}
{% for tag in collection.tags %}
{% if tag == 'Cat' %}
{% assign cat = 'true' %}
{% elsif tag == 'Dog' %}
{% assign dog = 'true' %}
{% endif %}
{% endfor %}
{% if dog == 'true' and cat == 'false' %}
<li>{{ collection.title | link_to: collection.url }}</li>
{% endif %}
{% endfor %}
I successfully get this list when I'm at homepage (telepienso.com). (See footer screenshot: A). I have the same exact code in collection.liquid and I get some of the collections but NOT all of them. (telepienso.com/collections/all). (See list on the right screenshot: B). Is there any restriction inside collection.liquid which can affect?
A screenshot (productos para perros list):
B screenshot (sección perros list):
This was the cause of the problem. The collections variable was being paginated.
By moving the code in the question outside of the paginate liquid tag, all collections are displayed in the sidebar (the same as the footer).
EDIT: The above link is broken because the question was deleted due to low traffic. I've copied the content from the question below for reference.
Shopify - issue accessing the collections global variable inside paginate
I would like to be able to access the collections global variable from within a paginated group of products, but the collections variable is also paginated if it is accessed within a paginate liquid tag.
For example (in collection.liquid):
{% for collection in collections %}
{{ collection.title }}
{% endfor %}
<br />
{% paginate collection.products by 4 %}
{% for collection in collections %}
{{ collection.title }}
{% endfor %}
...
{% endpaginate %}
Output:
All Collection1 Collection2 Collection3 Collection4 Collection5 Collection6 Frontpage
All Collection1 Collection2 Collection3
The for loop before the paginate tag lists all collections as you would expect, but doing the same thing within the paginate tag causes collections to be paginated as well as the products I am actually wanting to paginate.
Is there a way to access the collections global variable within a paginated group of products without it also being affected by the pagination?
Why would I want to do this? It was causing this problem, and was not immediately obvious because the code using the collections variable was in a separate snippet to the code with the pagination.
EDIT 2: I can no longer reproduce this issue, it appears to have been fixed.