Shopify List Blog Tags - shopify

I'm trying to create a page in Shopify that loops through all the tags assigned to blog articles in a blog called 'Recipes', and simply list them all.
This seems simple, but my page is not outputting any tags.
-I have a blog created called 'Recipes'
-I have blog posts assigned to the 'Recipes' blog, and each one has a different tag assigned.
-I created a template (page.blogtags.liquid), and assigned that template to a page called 'Blog Tags'
My code for page.blogtags.liquid is as follows:
<div id=”blog-tags”>
<!– Loops over all the tags used in Recipes blog –>
{% for tag in blogs[recipes].tags %}
<h2>{{ tag }}</h2>
{% endfor %}
</div>
The page is outputting the div, but it contains nothing.
What am I doing wrong?

You are just missing quotes around recipes. Currently, Liquid is treating recipes as a variable and since it is undefined, it silently fails. All you needs is 'recipes' or "recipes" to specify that you want to access blogs property named recipes. So the code would become
<div id=”blog-tags”>
<!– Loops over all the tags used in Recipes blog –>
{% for tag in blogs['recipes'].tags %}
<h2>{{ tag }}</h2>
{% endfor %}
</div>
Alternatively, you can also do blogs.recipes.tags
<div id=”blog-tags”>
<!– Loops over all the tags used in Recipes blog –>
{% for tag in blogs.recipes.tags %}
<h2>{{ tag }}</h2>
{% endfor %}
</div>

Related

Limit number of tags in content

there is that old blog post to get a list of categories and tags from the content.
I only found tag_cloud as the only plugin dealing with tags no further mention in the documentation
Is there any way to limit the usable tags e.g. through the configs ?
One option is you can define a ALLOWED_TAGS variable in pelicanconf.py to contain the tags that you want to allow, then in places where tags are placed you can add a JINJA if block to allow only these tags
#pelicanconf.py
...
ALLOWED TAGS = ("tag1", "tag2", "tag3", tag4")
Example of generating tags for an article below
<div class="article-tags">
{% for tag in article.tags %}
{% if tag in ALLOWED_TAGS %}
<{{tag}}</span>
{% endif %}
{% endfor %}
</div>

How to combine for and where clause in Liquid

I'm currently working on a shopify site and need to create a filter on a products page. My goal is to have primer paints show up in a different section of the product collection page. What I'm having trouble with is how to filter for primers. We have a tag set up in the product page named "Primer". What I want is for the loop to check whether a product has the primer tag, and if so, display that as one of the products in the loop. I'm relatively new to Liquid, so I don't know how to combine clauses if that's possible. I've looked up the "Where" clause, but don't entirely understand how it works.
Here is the code as it stands:
<div class="{% if settings.show_collection_sidebar %}desktop-10{% else
%}desktop-12{% endif %} tablet-6 mobile-3" id="bside">
<div id="product-loop">
{% for product in collection.products %}
<div class="product {% if settings.products_per_row == '3' %}
desktop-4{% cycle ' first', '', ' last' %}
{% elsif settings.products_per_row == '4' %}
desktop-3{% cycle ' first', '', '', ' last' %}
{% endif %} tablet-half mobile-half"
id="prod-{{ product.id }}"
data-alpha="{{ product.title }}"
data-price="{{ product.price }}">
{% include 'product-listing' %}
</div>
{% endfor %}
</div>
</div>
How could I filter for the desired results? I've tried {% if product.tags contains 'Primer' %} in quite a few places, but to no avail.
Thanks for your help.
Have you considered using two collections to accomplish what you're after?
If you made a dynamic ("Smart") collection for all your primers (Let's assume the handle for the collection is 'primer'), you can access that collection at any time through Liquid:
{% assign primer_collection = collections['primer'] %}
{% for product in primer_collection.products %}
<h2>HAVE SOME {{ product.title }}!</h2>
{% endfor %}
Then, if you wanted to exclude all of your primer products from the main collection, create a collection named 'all' (or at least with the handle 'all' - the actual title doesn't strictly matter - see footnote). By default, the 'All' collection is, true to its name, every product in your store. However, if you create your own 'all' collection, you can define it to mean "Everything except certain items" - in your case, 'everything but the primer'
Having Shopify pre-filter everything for you through the collections themselves greatly reduces the headaches of trying to apply filters after-the-fact and dealing with misleading item counts, uneven pagination, etc.
Handles: At the bottom of each collection and product in your Shopify admin is the SEO settings. Editing these allows you to change what the handle for the collection/product is, and this is what Shopify uses to look up your collection/product internally

How to display best seller products on front-page using Shopify

I have a dev theme for a shopify store. Basically it's a child theme. I would like to get how to display the best selling products on the front page. I tried something like this but no luck maybe because the sample is outdated.
<div class="row">
{% for product in collections["all"].products | limit:12 | sort_by: 'best-seller' %}
{% include 'product-grid-item' with "all" %}
{% endfor %}
</div>
Is there any way we can create something like this? Thanks in advance.
An easy way of doing it, as sort on Shopify won't work with the value best-seller, is to create a new Collection called (for example) Best Sellers where you have all your products (you could set as the sole condition for product price to be greater than $0 if it applies on your store).
Then, set that collection sorting to By best selling on your admin dashboard.
Finally, use Liquid in a similar way as per the following:
<div class="row">
{% for product in collections.best-sellers.products | limit:12 %}
{% include 'product-grid-item' with "all" %}
{% endfor %}
</div>

Multiple linklists on shopify categories (sidebar)

Yet another shopify question. I have a sidebar on shop/collections page
settings.sidebar_categoryblock_linklist
Which shows links to my main collecions: men/woman/kinds ect.
Yet I have another collection list based on product tags:
Winter/Autumn/Casual/Business etc
How do I get to display them on the sidebar? Meaning how can I put several linklists as categories link lists?
Thanks in advance
Julia
In a collection page, you have access to all the tags (unique) that the products have. You can use these tags to see if the belong to any collection and then display them. The code is as follows:
{% for tag in collection.all_tags %}
{% assign c_collection = collections[tag] %} // c_collection is used so the current display page's collection doesn't get disturbed
{% if c_collection.title != '' %}
{{ tag | link_to: c_collection.url,c_collection.title }} // not sure about this, but you can use proper html as well here
{% endif %}
{% endfor %}

Shopify: List ONLY active tag

I imagine someone has created this solution before and for the life of me I can't make sense of it.
I am using the following code to create a list of tags for my Men's T-Shirt department:
<ul>
<li class="clearfix filter-type">Garment Type</li>
{% assign tags = 'Short Sleeve, Long Sleeve, Polo, Crew %}
{% for tag in tags %}
{% if current_tags contains tag %}
<li class="selected">{{ '-' | link_to_remove_tag: tag }} {{ tag }}</li>
{% elsif collection.all_tags contains tag %}
<li>{{ tag | link_to_add_tag: tag }}</li>
{% endif %}
{% endfor %}
</ul>
It works as expected, but what I am trying to accomplish is if one of the tags is selected, say "Short Sleeve", then the list should display ONLY "- Short Sleeve" and nothing else. Not allowing the customer to select any other tags from that group. Simply because, if something is tagged "Short Sleeve" it is not "Long Sleeve"
As it is working now, the customer could select "Short Sleeve" and then select "Long Sleeve" resulting in no results.
Any guidance would be greatly appreciated, thanks!
The Filters page on the Shopify wiki states:
link_to_add_tag Links to products that have the given tag and any previously applied tags
link_to_tag Creates a link to the tag page
So, simply change link_to_add_tag to link_to_tag.
Also see:
Managing Subcategories using Tags. This article uses link_to_tag to filter products by colour.
Related discussion on Shopify forum, Only one Tag at a time.