Excluding a blog topic from a Topics list

SOLVE
Regular Contributor

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!

Reply
0 Upvotes
1 Accepted solution

Accepted Solutions
Highlighted
Regular Advisor

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;
}

 

Reply
0 Upvotes
9 Replies 9
Highlighted
Esteemed Advisor | Partner

@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. 

- Jonathan Sumner
Reply
0 Upvotes
Highlighted
Regular Contributor

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', 8) %}

<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', 8) %}
<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 

 

Reply
0 Upvotes
Highlighted
Esteemed Advisor | Partner

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.

- Jonathan Sumner
Reply
0 Upvotes
Highlighted
Regular Advisor

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;
}

 

Reply
0 Upvotes
Highlighted
Regular Contributor

Great idea! Thanks!

Reply
0 Upvotes
Highlighted
New Contributor

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') %}
 
 
Reply
0 Upvotes
Highlighted
Occasional Contributor

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

content markup goes here

{% endunless %}

Reply
0 Upvotes
Highlighted
Esteemed Contributor | Gold Partner

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 %}
Highlighted
Regular Contributor | Diamond Partner

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 %}
Reply
0 Upvotes