We’re trying to code a custom post filter via HubL Module. The links are working fine but we’re taking a hard time to make the blog shows the correct number. Found a old post in the forum but it counts like blog_total_pages instead of the tags.
{% set my_tags = blog_tags('default', 250) %}
<ul>
{% for item in my_tags %}
<li><a href="{{ blog_tag_url(group.id, item.slug) }}">{{ item }} ({{item.live_posts}})</a></li>
{% endfor %}
</ul>
Even just pasting the {{item.live_posts}}, the counter still doesn’t work. Is there a specific HubL variables to list all our blog_tags and be able to list them in separated <li>?
Thanks
EDIT: To make it simplier, here’s our module right now:
I tested the code you posted and it’s working how it should on my end. Can you post a screenshot of what it’s outputting for you? Are you using that exact code or did you make any changes?
@Vitni The blog_tags function doesn’t have a parameter for only showing particular tags so you would need a separate array to check against and then you’ll only want a single li inside your for loop as the loop will print the content inside it for every item in the loop.
{% set all_tags = blog_tags('default', 250) %}
{% set my_tags = ['Tag 1 Name', 'Tag 2 Name', 'Tag 3 Name'] %} // Replace the names here with the tag names you want listed
<ul>
{% for item in all_tags %}
{% if item.name in my_tags %}
<li class="{{ item.slug }}">
<a href="{{ blog_tag_url(group.id, item.slug) }}">{{ item.name }}<span class="filter-link-count" dir="ltr"> ({{item.live_posts}}) </span></a>
</li>
{% endif %}
{% endfor %}
</ul>
@Vitni Hm, it might have an issue with the accented letters. May need to use the slug instead of the name. The slug would be the hyphenated version of the tag that is used in the tag URL. Example: A tag named “Creative Marketing” would have a slug of “creative-marketing”.
{% set all_tags = blog_tags('default', 250) %}
{% set my_tags = ['tag-name-slug', 'tag-name-slug', 'tag-name-slug'] %} // Replace the names here with the tag slug (this is the hyphenated version of the name that would show in the tag url)
<ul>
{% for item in all_tags %}
{% if item.slug in my_tags %}
<li class="{{ item.slug }}">
<a href="{{ blog_tag_url(group.id, item.slug) }}">{{ item.name }}<span class="filter-link-count" dir="ltr"> ({{item.live_posts}}) </span></a>
</li>
{% endif %}
{% endfor %}
</ul>