Blog Counter Post

Hello there,

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:

<div class="widget-module">
<ul> 
{% set my_tags = blog_tags('tag1', 'tag2', 'tag3', 3) %}
{% for item in my_tags %}
</ul>

 <ul style="width:70%;margin:auto;font-size:18px;"> 
 <li class="tag1">
 <a href="https://exampleblog.com/tag/tag1">Tag 1<span class="filter-link-count" dir="ltr"> ({{item.live_posts}}) </span></a>
 </li>

 <li class="tag2">
 <a href="https://exampleblog.com/tag/tag2">Tag 2<span class="filter-link-count" dir="ltr"> ({{item.live_posts}}) </span></a>
 </li>

 <li class="tag3">
 <a href="https://exampleblog.com/tag/tag3">Tag 3<span class="filter-link-count" dir="ltr"> ({{item.live_posts}}) </span></a>
 </li>
 </ul>

{% endfor %}
 </div>

We found out {{item.live_posts}} is the blog counter but we can’t manage it to work.

Hey @Vitni

Welcome to the Community!

Thank you for sharing this information and some context. I’ll invite to this conversation a few experts that can share their thoughts with you.

Hey @mangelet @alyssamwilie what would you advise in this case?

Thanks

Sharon

@Vitni

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?

Hi @alyssamwilie

Thanks for the heads up. Yes, simply pasting the code works fine, but it lists all the tags we used like the image below:

We’d like to make the code shows specific tags listed in red.

However, the bullets need to be customized too, so our module have a css with list-style-image from these <li>

40125iF3CDF2BB20F278F1.png

All we need is to make this {{item_live_posts}} shows their specific count number. I edited my previous post with our html right now.

Thanks

@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>

@alyssamwilie Thank you for the clarification. Replaced the tag names but unfortunately it returned a blank preview with no results.

Besides replacing the tags name, do I need to change something else?

@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>

@alyssamwilie Yes!!! It works like a charm. Thank you so much for the solution :slightly_smiling_face: