CMS Development

ik30
Participant

How to remove a post from the blog listing.

SOLVE

I successfully created a featured image at the top of the page. I used a "featured-blog" tag to pull the blog image I wanted. Now I want to remove the blog from the blog list. 

Is there a way to remove all blogs inside the "featured-blog" topic. I'm new to Hubl so not sure how to go about editing the "for content in contents" loop.

 

 

Screen Shot 2018-10-01 at 12.06.57 PM.pngFeatured Blog ImageFeatured Blog Image

0 Upvotes
1 Accepted solution
Stephanie-OG
Solution
Key Advisor

How to remove a post from the blog listing.

SOLVE

Hi there!

 

I wrote a blog post on how to do this recently and added in some code for "Excluding Featured Posts from the Remaining Posts" you might find handy, it uses conditionals to both include and exclude the "featured-blog" tag:

 

{# First loop: featured posts #}
{% for content in contents %}
   {% for topic in content.topic_list %}
     {% if topic.name == 'featured-blog' %}     
        {# Add your featured post markup here #}
     {% endif %}
   {% endfor %}
{% endfor %}

{# Second loop: all other posts #}
{% for content in contents %}
   {% for topic in content.topic_list %}
      {% if topic.name != 'featured-blog' %}
         {# Add the markup for the rest of your posts here #}
      {% endif %}
   {% endfor %}
{% endfor %}


 I hope that helps!

 


Stephanie O'Gay GarciaHubSpot Design / Development

Website | Contact

 

If this helped, please mark it as the solution to your question, thanks!

View solution in original post

2 Replies 2
Stephanie-OG
Solution
Key Advisor

How to remove a post from the blog listing.

SOLVE

Hi there!

 

I wrote a blog post on how to do this recently and added in some code for "Excluding Featured Posts from the Remaining Posts" you might find handy, it uses conditionals to both include and exclude the "featured-blog" tag:

 

{# First loop: featured posts #}
{% for content in contents %}
   {% for topic in content.topic_list %}
     {% if topic.name == 'featured-blog' %}     
        {# Add your featured post markup here #}
     {% endif %}
   {% endfor %}
{% endfor %}

{# Second loop: all other posts #}
{% for content in contents %}
   {% for topic in content.topic_list %}
      {% if topic.name != 'featured-blog' %}
         {# Add the markup for the rest of your posts here #}
      {% endif %}
   {% endfor %}
{% endfor %}


 I hope that helps!

 


Stephanie O'Gay GarciaHubSpot Design / Development

Website | Contact

 

If this helped, please mark it as the solution to your question, thanks!

ik30
Participant

How to remove a post from the blog listing.

SOLVE

Hi Stephanie

Thank you for replying so fast. I tried adding the second snippet you mentioned but it didn't work. I am pasting the code I have below incase that helps troubleshoot my issue. Also I only needed the second loop as I did the first loop in a seperate blog content module. 

EDIT: Your solution worked, thank you! I had multiple tages so I was still seeing the blog. Now it's duplicating a blog with multiple tags. Creating a new post for that.

{% for content in contents %}
{% for topic in content.topic_list %}
{% if topic.name != 'featured-blog' %}
<div class="post-item">
{% if content.post_list_summary_featured_image %} <div class="hs-featured-image-wrapper"> <a href="{{content.absolute_ukl}}" title="" class="hs-featured-image-link"> <img src="{{ resize_image_url( content.post_list_summary_featured_image,767 ) }}" class="hs-featured-image" alt="{{ content.featured_image_alt_text | escape }}"> </a> </div> {% endif %} {% if not simple_list_page %} <div class = "post-shell"> <div class="post-header"> <h2><a href="{{content.absolute_url}}">{{ content.name }}</a></h2> </div> <div class="post-body clearfix"> <!--post summary--> {{ content.post_list_content|safe }} </div> {% if content_group.show_summary_in_listing %} <a class="more-link" href="{{ content.absolute_url }}">> READ MORE</a> {% endif %} {# <div class="custom_listing_comments"> {% set comments_number = content.comment_list|length %} {% set comments_label = "Comment" if comments_number == 1 else "Comments" %} {{ comments_number }} {{ comments_label }} <a href="{{content.absolute_url}}#comments-listing">Click here to read/write comments</a> </div> - CHANGE MADE TO REMOVE COMMENTS ON LISTING TEMPLATE BY NICK POTTS 28-JUN-2018 #} {# if content.topic_list %} <p id="hubspot-topic_data"> Topics: {% for topic in content.topic_list %} <a class="topic-link" href="{{ blog_tag_url(group.id, topic.slug) }}">{{ topic.name }}</a>{% if not loop.last %},{% endif %} {% endfor %} </p> {% endif #} </div> {% else %} <h2 class="post-listing-simple"><a href="{{content.absolute_url}}">{{ content.name }}</a></h2> {% endif %} </div> {% endif %} {% endfor %} {% endfor %}

 

0 Upvotes