CMS Development

cwilbanks
Member

Exclude all blog posts with a specific tag from blog listing page

SOLVE

Hello, 

 

Is there a way to exclude all posts with a specific tag from my blog listing page but show all others?

 

Thank you

0 Upvotes
1 Accepted solution
cwilbanks
Solution
Member

Exclude all blog posts with a specific tag from blog listing page

SOLVE

Figured it out:

 

{% unless 'topic goes here' in content.topic_list|map('name') %}

content markup goes here

{% endunless %}

View solution in original post

0 Upvotes
5 Replies 5
cwilbanks
Solution
Member

Exclude all blog posts with a specific tag from blog listing page

SOLVE

Figured it out:

 

{% unless 'topic goes here' in content.topic_list|map('name') %}

content markup goes here

{% endunless %}

0 Upvotes
drbipes
Contributor

Exclude all blog posts with a specific tag from blog listing page

SOLVE

Can you elaborate on how you got this to work?  I am very new to hubl.

{% unless 'Tip' in content.topic_list|map('name') %}
                   {% for content in topic_posts %}
markup
{% endunless %}

I know this isn't right.... can you use this with {% content in contents %}  ?

 

0 Upvotes
cwilbanks
Member

Exclude all blog posts with a specific tag from blog listing page

SOLVE

So this is how I made use of it. You should be able to switch out 'topic_list' for the variables listed here under blog variables: https://designers.hubspot.com/docs/hubl/hubl-supported-variables. 

 

{% for topic in content.topic_list %}
{% unless 'Topic to Exclude Here' in content.topic_list|map('name') %}
        {% if loop.first %}
            {% set related_posts = blog_recent_topic_posts('default', 5 ) %}
            {% for post in related_posts %}
                {% unless content.absolute_url == post.absolute_url %}
                    <div class="topic post container class">
                        <div class=" some title class"><a href="{{post.absolute_url}}">{{ post.name}}</a></div>
                        <div class="some post image class"><img src="{{ post.featured_image }}" alt="{{ post.name }}"></div>
                    </div>
                {% endunless %}

            {% endfor %}
        {% endif %}
{% endunless %}
0 Upvotes
drbipes
Contributor

Exclude all blog posts with a specific tag from blog listing page

SOLVE

I can't get that code to produce any results.  It also says I have a missing {% endfor %}.

 

This is how I tried it, was 'name' supposed to be replaced?

{% for topic in content.topic_list %}
{% unless 'Tip' in content.topic_list|map('name') %}
        {% if loop.first %}
            {% set related_posts = blog_recent_topic_posts('default', 5 ) %}
            {% for post in related_posts %}
                {% unless content.absolute_url == post.absolute_url %}
                    <div class="topic post container class">
                        <div class=" some title class"><a href="{{post.absolute_url}}">{{ post.name}}</a></div>
                        <div class="some post image class"><img src="{{ post.featured_image }}" alt="{{ post.name }}"></div>
                    </div>
                {% endunless %}

            {% endfor %}
        {% endif %}
{% endunless %}
                  {% endfor %}
0 Upvotes
cwilbanks
Member

Exclude all blog posts with a specific tag from blog listing page

SOLVE

The code looks right did you place the module into the blog template?

{% for topic in content.topic_list %}
{% unless 'Tip' in content.topic_list|map('name') %}
        {% if loop.first %}
            {% set related_posts = blog_recent_topic_posts('default', 5 ) %}
            {% for post in related_posts %}
                {% unless content.absolute_url == post.absolute_url %}
                    <div class="topic post container class">
                        <div class=" some title class"><a href="{{post.absolute_url}}">{{ post.name}}</a></div>
                        <div class="some post image class"><img src="{{ post.featured_image }}" alt="{{ post.name }}"></div>
                    </div>
                {% endunless %}
            {% endfor %}
        {% endif %}
{% endunless %}
{% endfor %} 

 It doesn't show anything until the module is placed into the blog template.

0 Upvotes