CMS Development

RyanPatterson
Contributeur | Partenaire solutions Platinum
Contributeur | Partenaire solutions Platinum

Exclude the most recent post from "featured" topic on blog listing page (listing template)

Résolue

I'm currently building a blog listing page template that has a featured post at the top full-width. It pulls the most recent posts tagged with "featured". This is build in a custom HubL module. 

 

Then below this custom HubL module, I have the normal blog content module, formatted to put the posts in rows of 3. 

 

I have all that working great. However, the featured post is also showing up in the blog content module (listing template). 

 

Here is my code so far. Please keep in mind I'm completely new to HubL.

 

Custom HubL module for featured post

    {% set topic_posts = blog_recent_topic_posts('{{ content.parent_blog.id }}', 'featured', 1 ) %}
    
    {% for topic_post in topic_posts %}
        {% if loop.index <= 1 %}
        
            {% if topic_post.post_list_summary_featured_image %}
            
                <div class="featured-post-image-wrapper">
                    
                    <img src="{{ topic_post.post_list_summary_featured_image }}" class="post-featured-image" alt="{{ topic_post.featured_image_alt_text }}" />
                    
                </div>
            
            {% endif %}
            <div class="h2-accent-line"></div>
             <h2 class="featured-post-title">{{ topic_post.name }}</h2>
             <p>{{ topic_post.post_list_content|safe }}</p>
             <a class="button" href="{{ topic_post.absolute_url }}">Read More</a>
             
    
         {% endif %}
    {% endfor %}

Blog Content Module (listing template)

<div class="blog-section">
    <div class="blog-listing-wrapper cell-wrapper">
        <div class="blog-section">
            <div class="blog-listing-wrapper cell-wrapper">
        {# simple_list_page indicates the "blog/all" page, which is a list of links to every blog post #}
                <div class="post-listing{% if simple_list_page %}-simple{% endif %}">
                    {% for content in contents %}
                            {% if loop.index0 % 3 == 0 %}
                            <div class="grid-row">
                            {% endif %}
                            <div class="post-item">
                                {% if not simple_list_page %}
                                    <div class="post-header">
                                        {% if content.post_list_summary_featured_image %}
                                            <div class="hs-featured-image-wrapper">
                                                <a href="{{content.absolute_url}}" title="" class="hs-featured-image-link">
                                                    <img src="{{ content.post_list_summary_featured_image }}" class="" alt="{{ content.featured_image_alt_text | escape }}">
                                                </a>
                                            </div>
                                        {% endif %}
                                        <h2><a href="{{content.absolute_url}}">{{ content.name }}</a></h2>
                                    </div>
                                    <div class="post-body clearfix">
                                        <p>{{ content.post_list_content|striptags|truncate(120, breakword=False, end='...') }}</p>
                                    </div>
                                    {% if content_group.show_summary_in_listing %}
                                        <a class="more-link" href="{{ content.absolute_url }}">Read More</a>
                                    {% endif %}
                                {% else %}
                                    <h2 class="post-listing-simple"><a href="{{content.absolute_url}}">{{ content.name }}</a></h2>
                                {% endif %}
                            </div>
                            {% if loop.index0 % 3 == 2 %}
                            </div><!-- end .grid-row -->
                            {% endif %}
                    {% endfor %}
                </div>
                {% if not simple_list_page %}
                <div class="blog-pagination">
                    {% if last_page_num %}
                        <a class="previous-posts-link" href="{{ blog_page_link(last_page_num) }}">Previous</a>
                    {% endif %}
                        <a class="all-posts-link" href="{{ blog_all_posts_url(group.id) }}">All posts</a>
                    {% if next_page_num %}
                        <a class="next-posts-link" href="{{ blog_page_link(next_page_num) }}">Next</a>
                    {% endif %}
                </div>
                {% endif %}
            </div>
        </div>
    </div>
</div>

What I'm trying to achieve is in my listing template, remove the most recent post tagged "featured", the one that shows up in they HubL module. 

 

I don't want to exlude all featured posts, just the most recent post that shows up in the custom HubL module. 

 

I tried adding an unless statement directly inside the "content in contents" for loop (sorry for the weird indentation)

{% unless 'featured' in content.topic_list|map('name') %}
    {% if loop.index0 % 3 == 0 %}
                            <div class="grid-row">
                            {% endif %}
                            <div class="post-item">
                                {% if not simple_list_page %}
                                    <div class="post-header">
                                        {% if content.post_list_summary_featured_image %}
                                            <div class="hs-featured-image-wrapper">
                                                <a href="{{content.absolute_url}}" title="" class="hs-featured-image-link">
                                                    <img src="{{ content.post_list_summary_featured_image }}" class="" alt="{{ content.featured_image_alt_text | escape }}">
                                                </a>
                                            </div>
                                        {% endif %}
                                        <h2><a href="{{content.absolute_url}}">{{ content.name }}</a></h2>
                                    </div>
                                    <div class="post-body clearfix">
                                        <p>{{ content.post_list_content|striptags|truncate(120, breakword=False, end='...') }}</p>
                                    </div>
                                    {% if content_group.show_summary_in_listing %}
                                        <a class="more-link" href="{{ content.absolute_url }}">Read More</a>
                                    {% endif %}
                                {% else %}
                                    <h2 class="post-listing-simple"><a href="{{content.absolute_url}}">{{ content.name }}</a></h2>
                                {% endif %}
                            </div>
                            {% if loop.index0 % 3 == 2 %}
                            </div><!-- end .grid-row -->
       {% endif %}
{% endunless %}

 

and it did hide the featured post, but then it messed up the formatting. It kept the first 3 in a row, but all after that were not getting wrapped in the .grid-row div.

 

Any help would be greatly appreciated

0 Votes
1 Solution acceptée
RyanPatterson
Solution
Contributeur | Partenaire solutions Platinum
Contributeur | Partenaire solutions Platinum

Exclude the most recent post from "featured" topic on blog listing page (listing template)

Résolue

Actually, I'm just going to close this posts. I had put wrapping divs around every 3rd post to put into rows of 3. Even if I use an {% unless %} statement to hide a any post with a certain topic assigned, it still gets counted as a loop iteration. I was really hoping to only hide the most recent post from the featured topic, but I'll just settle for hiding all featured posts. 

 

So I'm going to remove the wrapping divs on every 3rd post and just use the css grid layout to achieve what I'm wanting. 

Voir la solution dans l'envoi d'origine

0 Votes
6 Réponses
roisinkirby
Équipe de développement de HubSpot
Équipe de développement de HubSpot

Exclude the most recent post from "featured" topic on blog listing page (listing template)

Résolue

Hey @gregorsmith could you please share a link to the preview/live page you are working on so that the Community can assist? Thank you!

 

0 Votes
RyanPatterson
Contributeur | Partenaire solutions Platinum
Contributeur | Partenaire solutions Platinum

Exclude the most recent post from "featured" topic on blog listing page (listing template)

Résolue

???? I think you replied to the wrong post

0 Votes
roisinkirby
Équipe de développement de HubSpot
Équipe de développement de HubSpot

Exclude the most recent post from "featured" topic on blog listing page (listing template)

Résolue

Hey @RyanPatterson in order to troubleshoot it would be helpful to see the blog listing page. Even if it's a preview link 🙂

0 Votes
RyanPatterson
Contributeur | Partenaire solutions Platinum
Contributeur | Partenaire solutions Platinum

Exclude the most recent post from "featured" topic on blog listing page (listing template)

Résolue

Ok, just threw me off cuz you said hey @gregorsmith , which is not me. 

 

But anyways, I can share a link, but I already posted my HubL code, so not sure how much seeing the front end is going to help. I'm not having a styling issue, it's a logic issue with the loop. 

 

https://app.hubspot.com/design-manager/3421671/templates/5572297876

0 Votes
RyanPatterson
Solution
Contributeur | Partenaire solutions Platinum
Contributeur | Partenaire solutions Platinum

Exclude the most recent post from "featured" topic on blog listing page (listing template)

Résolue

Actually, I'm just going to close this posts. I had put wrapping divs around every 3rd post to put into rows of 3. Even if I use an {% unless %} statement to hide a any post with a certain topic assigned, it still gets counted as a loop iteration. I was really hoping to only hide the most recent post from the featured topic, but I'll just settle for hiding all featured posts. 

 

So I'm going to remove the wrapping divs on every 3rd post and just use the css grid layout to achieve what I'm wanting. 

0 Votes
heytricia
Contributeur

Exclude the most recent post from "featured" topic on blog listing page (listing template)

Résolue

Hey!

 

I'm faced with your exact same scenario as seen here:  https://www.calibermind.com/intelligent-marketer/

 

Your solution helped, but I'd like to overcome the post-count issue. I have post listing pages set to show 9 posts - so when my featured post  is removed, the first page only shows 8. Is there a way to overcome this? I've temporarily set to show 10 as a quick fix... but long term that will set additional pages to have one too many posts.

It also stinks that we have to remember to remove the featured tag from older posts as we assign to new ones... so that they can be seen in the listing. Were you able to find a way to say don't show the first post tagged featured?

 

Thanks!