CMS Development

drewherr
Member

Add blog tags/topics name to recent posts listing

I'm looking for a way to dynamically change a header to display the individual recent post tag on a hubl coded blog.

 

I've tried using this, but I believe I need a "for" statement...

<div class="title-bar">
    <h2>Recent {{ topic.name }} Posts</h2>
</div>

 

Here is a link to an example - https://toolkit.serentcapital.com/blog/tag/sales#recent-posts

 

I am trying to get it to display Recent "Sales" Posts.

 

Thanks for the help!

0 Upvotes
2 Replies 2
lscanlan
HubSpot Alumni
HubSpot Alumni

Add blog tags/topics name to recent posts listing

Hi @drewherr,

 

I used to accomplish this with something like this:

 

{% if topic %}
    {% set string_to_split = content.title %}
	{% set newArray = string_to_split|split('|', 2) %}
	{% for item in newArray %}
		{% if loop.last %}
			<h2 style="text-align: center;">{{ item }}</h2>
		{% endif %}
	{% endfor %}
{% endif %}

So basically pull the page title which should be auto-generated based on the topic. And then turn it into an array and get the latter part of the array, which is the text of the topic name.

 

Let me know if that helps with what you're trying to do?

 

 - Leland

Leland Scanlan

HubSpot Developer Support
0 Upvotes
drewherr
Member

Add blog tags/topics name to recent posts listing

Worked like a charm, thank you for the string_to_split idea. I wouldn't have come up with that. Much appreciated!

0 Upvotes