Alphabetize Blog Tags in Blog Navigation

SOLVE
Occasional Contributor

Currently, the blog topics in our blog (https://blog.femmepharma.com/menopositivity ) navigation are defaulting to show the most recently updated topic first. I would like them to display alphabetically.

 

I read these two posts and found neither to be helpful.

 

Make a Blog Topic List Appear in Alphabetical Order 

Alphabetize and re-arrange blog category buttons 

 

This is the blog navigation code set up by HubSpot when we moved the blog from WordPress. Any ideas?

 

<div class="title-with-topic-section">
<h1>{{ group.public_title }}</h1>
<a href="javascript&colon;;" class="reveal-blog-nav"><i class="fas fa-bars"></i> Blog Navigation</a>
{% set my_tags = blog_tags(group.id, 250) %}
<ul class="blog-nav" style="display:none;">
<li {% if !topic %}class="active"{% endif %}><a href="{{group.absolute_url}}">All Topics</a></li>
{% for item in my_tags %}
<li {% if topic and topic == item.slug %}class="active"{% endif %}><a href="{{ blog_tag_url(group.id, item.slug) }}">{{ item }}</a></li>
{% endfor %}
</ul>
</div>
{% if not simple_list_page %}

Thanks!

Reply
0 Upvotes
1 Accepted solution

Accepted Solutions
Regular Advisor

Hi there! 

 

You should be able to use the sort filter on your "my_tags". If you update your code to:

 

<div class="title-with-topic-section">
<h1>{{ group.public_title }}</h1>
<a href="javascript&colon;;" class="reveal-blog-nav"><i class="fas fa-bars"></i> Blog Navigation</a>
{% set my_tags = blog_tags(group.id, 250) %}
<ul class="blog-nav" style="display:none;">
<li {% if !topic %}class="active"{% endif %}><a href="{{group.absolute_url}}">All Topics</a></li>
{% for item in my_tags|sort(False, False, 'name') %}
<li {% if topic and topic == item.slug %}class="active"{% endif %}><a href="{{ blog_tag_url(group.id, item.slug) }}">{{ item }}</a></li>
{% endfor %}
</ul>
</div>
{% if not simple_list_page %}

 

They should appear in alphabetical order. 

 


Stephanie O'Gay Garcia

HubSpot CMS Design & Development

Website | Contact

 

If this helped, please mark it as the solution to your question, thanks!

2 Replies 2
Regular Advisor

Hi there! 

 

You should be able to use the sort filter on your "my_tags". If you update your code to:

 

<div class="title-with-topic-section">
<h1>{{ group.public_title }}</h1>
<a href="javascript&colon;;" class="reveal-blog-nav"><i class="fas fa-bars"></i> Blog Navigation</a>
{% set my_tags = blog_tags(group.id, 250) %}
<ul class="blog-nav" style="display:none;">
<li {% if !topic %}class="active"{% endif %}><a href="{{group.absolute_url}}">All Topics</a></li>
{% for item in my_tags|sort(False, False, 'name') %}
<li {% if topic and topic == item.slug %}class="active"{% endif %}><a href="{{ blog_tag_url(group.id, item.slug) }}">{{ item }}</a></li>
{% endfor %}
</ul>
</div>
{% if not simple_list_page %}

 

They should appear in alphabetical order. 

 


Stephanie O'Gay Garcia

HubSpot CMS Design & Development

Website | Contact

 

If this helped, please mark it as the solution to your question, thanks!

Highlighted
Occasional Contributor

That worked! Thank you so much!

Reply
0 Upvotes