CMS Development

dbarbara
Contributor

Excluding a blog topic from a Topics list

SOLVE

Hi,

 

I'm using a topic called 'Featured' to display a featured post at the top of the blog listing page and would like to keep the topic 'Featured' from displaying in the topics list.

 

This page has something close. It shows how to check for a particular topic, but doesn't include the markup.

 

 {% if 'Featured' in content.topic_list|map('name') %}
        Markup to print, if the topic "Featured" is set as a post's topic.
    {% endif %}

 Anyone know of some markup I could use to tell the topic 'Featured" NOT print?

 

Thanks!

0 Upvotes
1 Accepted solution
ndwilliams3
Solution
Key Advisor

Excluding a blog topic from a Topics list

SOLVE

Are you refering to the post filter that's just the list of topics and post count and links to the topic page? If so, it may be easier to just use CSS to hide it.

 

Find the id of the module, in my case it's hs_cos_wrapper_blog_topic_cloud, and the url of the featured topic page, for example: http://www.example.com/topic/featured. modify the following with your module id and the topic url and add to your stylesheet.

#hs_cos_wrapper_blog_topic_cloud .widget-module ul li a[href="http://www.example.com/topic/featured"] {
display:none;
}

 

View solution in original post

0 Upvotes
9 Replies 9
anders_grove
Contributor | Elite Partner
Contributor | Elite Partner

Excluding a blog topic from a Topics list

SOLVE

Best to use HubL for this.

 

Simply exclude the tag from your loop by either using unless or if !=.

 

See example below:

 

{% if content.topic_list %}
  <p id="hubspot-topic_data">
      {% for topic in content.topic_list %}
          {% unless topic.name == "Featured" %}
            <a class="topic-link" href="{{ blog_tag_url(group.id, topic.slug) }}">{{ topic.name }}</a>{% if not loop.last %},{% endif %}
          {% endunless %}
      {% endfor %}
  </p>
{% endif %}
0 Upvotes
benvanlooy
Top Contributor | Platinum Partner
Top Contributor | Platinum Partner

Excluding a blog topic from a Topics list

SOLVE

or simply

 

{% if !('Featured' in content.topic_list|map('name')) %}
        Markup to print, if the topic "Featured" is set as a post's topic.
    {% endif %}
cwilbanks
Member

Excluding a blog topic from a Topics list

SOLVE

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

content markup goes here

{% endunless %}

0 Upvotes
ndwilliams3
Solution
Key Advisor

Excluding a blog topic from a Topics list

SOLVE

Are you refering to the post filter that's just the list of topics and post count and links to the topic page? If so, it may be easier to just use CSS to hide it.

 

Find the id of the module, in my case it's hs_cos_wrapper_blog_topic_cloud, and the url of the featured topic page, for example: http://www.example.com/topic/featured. modify the following with your module id and the topic url and add to your stylesheet.

#hs_cos_wrapper_blog_topic_cloud .widget-module ul li a[href="http://www.example.com/topic/featured"] {
display:none;
}

 

0 Upvotes
dbarbara
Contributor

Excluding a blog topic from a Topics list

SOLVE

Great idea! Thanks!

0 Upvotes
eparker
Participant

Excluding a blog topic from a Topics list

SOLVE

A simple hubl solution that works, just add the following to your anchor tag:

 

{% if topic.name == 'featured' %}style="display: none;"{% endif %}

 

There is no need for:

 {% if 'Featured' in content.topic_list|map('name') %}
 
 
0 Upvotes
Jsum
Key Advisor

Excluding a blog topic from a Topics list

SOLVE

@dbarbara it's the same login as in that page in reverse,

 

 {% if 'Featured' in content.topic_list|map('name') %}
        Markup to print, if the topic "Featured" is set as a post's topic.
    {% endif %}

 does something if the condition is true

 {% unless 'Featured' in content.topic_list|map('name') %}
        Markup to print, if the topic "Featured" is set as a post's topic.
    {% endunless %}

does something if the condition is not true. 

 

Place an "unless" statement inside of your {% for content in contents %} statement that checks for the topic inside of the content.topic_list and it shouldn't display the post if it has the "featured" topic assigned to it. You should be aware though that it will not show ANY posts containing the "featured" topic. 

0 Upvotes
dbarbara
Contributor

Excluding a blog topic from a Topics list

SOLVE

Am just trying to hide the Featured topic in the Topics List module, not the actual posts.

 

So I need to hide the "Featured" topic somewhere in here:

 

<div class="span12 widget-span widget-type-raw_jinja blog-topics" style="" data-widget-type="raw_jinja" data-x="0" data-w="12">
{% set my_topics = blog_topics('default', 😎 %}

<ul>
<li class="tab-all" class="active">
<a href="{{ group.absolute_url }}">All</a></li>
{% for item in my_topics %}
<li><a href="{{ group.absolute_url }}/topic/{{item.slug}}">{{ item }}</a></li>
{% endfor %}
</ul>
</div><!--end widget-span --> 

And also here:

<div class="span12 widget-span widget-type-raw_jinja blog-topics-buttons" style="" data-widget-type="raw_jinja" data-x="0" data-w="12">
{% set my_topics = blog_topics('default', 😎 %}
<h3 style="text-align:center; margin: 0">Search By Topic</h3>
<ul>
{% for item in my_topics %}
<li><a href="{{ group.absolute_url }}/topic/{{item.slug}}">{{ item }}</a></li>
{% endfor %}
</ul></div><!--end widget-span 

 

0 Upvotes
Jsum
Key Advisor

Excluding a blog topic from a Topics list

SOLVE

This should work:

{% for content in contents %}
    {% for topic in content.topic_list %}
        {% unless 'Featured' in content.topic_list|map('name') %}
        
              <span class="topic-link">{{ topic.name }}</span>

        {% endunless %}
    {% endfor %}
{% endfor %}

In your listing markup you should be looping through the topics of each blog to display the topics per blog on the listing page. Use this unless condition inside that loop and it should omit the "featured" topic.

0 Upvotes