How to add description for blog post article tag

Solved

How to add description for blog post article tag

lujbek
Tourist
10 0 1

As far as I know when we create a new tag we are able to define the tag name. Is there any way to define an extra information like tag description . Because we want to show on the banner the heading/description associated with select tag. How can we do that ? 

 

lujbek_0-1702910206460.png

 

Thanks

 

Accepted Solution (1)

pawankumar
Shopify Partner
652 96 119

This is an accepted solution.

Hi @lujbek 
I hope you are doing well.
It will require some advance knowledge of liquid
You can do that by using metafields/metaobjects
Thanks!

- Need a Shopify developer? Chat on WhatsApp +91-9467121281
- Coffee Tip: Buymeacoffee  | Email: thepkpawankumar@gmail.com
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
Best regards,
Pawan

View solution in original post

Replies 6 (6)

pawankumar
Shopify Partner
652 96 119

This is an accepted solution.

Hi @lujbek 
I hope you are doing well.
It will require some advance knowledge of liquid
You can do that by using metafields/metaobjects
Thanks!

- Need a Shopify developer? Chat on WhatsApp +91-9467121281
- Coffee Tip: Buymeacoffee  | Email: thepkpawankumar@gmail.com
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
Best regards,
Pawan
lujbek
Tourist
10 0 1

It worked. Thanks for your advise

ri2
Excursionist
12 0 0

Any tips on how to add a metafield to a blog post tag? The Shopify admin panel doesn't provide an option for this.

pawankumar
Shopify Partner
652 96 119

Hi @ri2 
You can use metaobject for this, you can use 2 fields
a. One for blog post tag --> it can act as an identifier 
b. Actual metafield to use
so, you can search among metaobject entries by post tag and then use the matching metafield
Thanks!

- Need a Shopify developer? Chat on WhatsApp +91-9467121281
- Coffee Tip: Buymeacoffee  | Email: thepkpawankumar@gmail.com
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
Best regards,
Pawan
ri2
Excursionist
12 0 0

That makes sense. Thanks for the reply!

ri31
Shopify Partner
15 1 3

Follow up for anyone who needs this:

 

  1. Created a new metaobject type. In this example code, I use the key custom_blog_post_tag
  2. Add a single-line text field "Name" (key "name" in the example)
  3. Add a rich text field to the metaobject. In this example, I actually have 2 fields and they have the keys "short_description" and "description"
  4. Create metaobject entries to match your blog post tags. 1 metaobject entry per tag. Fill out the name and description values for each metaobject, ensuring that the name field exactly matches each of your existing blog post tags.
  5. Go to the theme customizer and select the blog template
  6. Add a custom liquid section with the following code:

 

{% for custom_tag in shop.metaobjects.custom_blog_post_tag.values %}
{%if custom_tag.name == current_tags.first %}
{{ custom_tag.short_description | metafield_tag }}
{{ custom_tag.description | metafield_tag }}
{% endif %}
{% endfor %}

 

This code will not return anything if a meta object is not found that matches the current tag. Since the blog home page itself (eg /blogs/blog/) doesn't have a tag assigned, it won't show anything on the blog home page, only on the pages for the tags (eg /blogs/blog/tagged/tag-name)