简体   繁体   中英

Shopify List Blog Tags

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM