CMS Development

jwill377
Member

Display current page blog tag when post has multiple tags

SOLVE

Hi all! Right now I am setting blog posts to only display the first blog topic in the loop, but I would like for the correct tag to display within each blog category page.  Here is the code I am currently using:

<div class="post-list">
<div class="blog-index__post blog-index__post--small">
<a class="blog-index__post-image blog-index__post-image--small"
{% if content.featured_image %}
style="background-image: url('{{ content.featured_image }}')";
{% endif %}
href="{{ content.absolute_url }}"></a>
<div class="blog-index__post-content blog-index__post-content--small">
{% for tag in content.tag_list %}{% if loop.first %}<h5><a href="{{ blog_tag_url(group.id, tag.slug) }}" rel="tag">{{ tag.name }}</a></h5>{% endif %}{% endfor %}
<h2><a href="{{ content.absolute_url }}">{{ content.name|truncate(70, True, '...') }}</a></h2>
</div>
</div>
</div>

0 Upvotes
1 Accepted solution
Teun
Solution
Recognized Expert | Diamond Partner
Recognized Expert | Diamond Partner

Display current page blog tag when post has multiple tags

SOLVE

Hi @jwill377 ,

Try this:

<div class="post-list">
  <div class="blog-index__post blog-index__post--small">
    <a class="blog-index__post-image blog-index__post-image--small" {% if content.featured_image %}
      style="background-image: url('{{ content.featured_image }}')" ; {% endif %} href="{{ content.absolute_url }}"></a>
    <div class="blog-index__post-content blog-index__post-content--small">
      {% for tag in content.tag_list %}
        {% if tag.slug in request.path %}
          <h5><a href="{{ blog_tag_url(group.id, tag.slug) }}" rel="tag">{{ tag.name }}</a></h5>
        {% endif %}
      {% endfor %}
      <h2><a href="{{ content.absolute_url }}">{{ content.name|truncate(70, True, '...') }}</a></h2>
    </div>
  </div>
</div>


Learn more about HubSpot by following me on LinkedIn or YouTube

Did my answer solve your issue? Help the community by marking it as the solution.


View solution in original post

2 Replies 2
Teun
Solution
Recognized Expert | Diamond Partner
Recognized Expert | Diamond Partner

Display current page blog tag when post has multiple tags

SOLVE

Hi @jwill377 ,

Try this:

<div class="post-list">
  <div class="blog-index__post blog-index__post--small">
    <a class="blog-index__post-image blog-index__post-image--small" {% if content.featured_image %}
      style="background-image: url('{{ content.featured_image }}')" ; {% endif %} href="{{ content.absolute_url }}"></a>
    <div class="blog-index__post-content blog-index__post-content--small">
      {% for tag in content.tag_list %}
        {% if tag.slug in request.path %}
          <h5><a href="{{ blog_tag_url(group.id, tag.slug) }}" rel="tag">{{ tag.name }}</a></h5>
        {% endif %}
      {% endfor %}
      <h2><a href="{{ content.absolute_url }}">{{ content.name|truncate(70, True, '...') }}</a></h2>
    </div>
  </div>
</div>


Learn more about HubSpot by following me on LinkedIn or YouTube

Did my answer solve your issue? Help the community by marking it as the solution.


jwill377
Member

Display current page blog tag when post has multiple tags

SOLVE

This worked perfectly. Thank you so much!