We use cookies to make HubSpot's community a better place. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. To learn more, and to see a full list of cookies we use, check out our Cookie Policy (baked goods not included).
Sep 13, 2021 4:34 AM
Hi Team,
As we know we can use contents for blog listing(below is the screenshot).
Is there any way to exclude the first blog from the contents?
As per the template, we are showing a recent blog in the first row. And we are showing all the blogs from the second row(Below is our Blog Page URL).
https://www.columbusglobal.com/en/blog
Due to this functionality, the first blog is appearing twice which is a little bit disturbing.
Already tried with a similar kind of below functionality to hide the first blog from the list.
But it affecting to my pagination functionality.
Can anyone help here?
{% for topic_post in topic_posts %}
{% if loop.index <= 1 %}
****************************
{% endif %}
{% endfor %}
Solved! Go to Solution.
Sep 15, 2021 2:56 AM - edited Sep 15, 2021 7:24 AM
Hi @sjay,
done something similar recently with this code:
{% for content in contents %} {# fetch all blog posts #}
{% if loop.index >= 1 %} {# exclude first blog post #}
{# YOUR CONTENT GOES HERE #}
{% endif %}
{% endfor %}
best,
Anton
Sep 15, 2021 12:07 PM
Hi @Teun,
I would say that it depends how you're building your pagination.
I've wrote mine like this and it works flawlessly with the code above:
{% if not simple_list_page %}
<div class="row-fluid-wrapper">
<div class="row-fluid">
<div class="span12 col-12">
<div class="pagination">
{% if contents.total_page_count > 1 %}
<div class="blog-pagination">
{% set page_list = [-2, -1, 0, 1, 2] %}
{% if contents.total_page_count - current_page_num == 1 %}{% set offset = -1 %}
{% elif contents.total_page_count - current_page_num == 0 %}{% set offset = -2 %}
{% elif current_page_num == 2 %}{% set offset = 1 %}
{% elif current_page_num == 1 %}{% set offset = 2 %}
{% else %}{% set offset = 0 %}{% endif %}
<a class="pagination-prev {{ "blog-pagination__prev-link--disabled" if !last_page_num }}" href="{{ blog_page_link(last_page_num) }}">
<i class="fas fa-chevron-left"></i>
</a>
{% for page in page_list %}
{% set this_page = current_page_num + page + offset %}
{% if this_page > 0 and this_page <= contents.total_page_count %}
<a class="pagination-active {{ "me-blog-pagination__page--active" if this_page == current_page_num }}" href="{{ blog_page_link(this_page) }}">{{ this_page }}</a>
{% endif %}
{% endfor %}
<a class="pagination-next {{ "blog-pagination__next-link--disabled" if !next_page_num }}" href="{{ blog_page_link(current_page_num + 1) }}">
<i class="fas fa-chevron-right"></i>
</a>
</div>
{% endif %}
</div>
</div>
</div>
</div>
{% endif %}
when using {% if not loop.first %} could work too. To be honest never tried that. You could also write {% unless loop.first %}everything except the first post{% else %}first post{% endunless %}. Depends on how you want to build your logic but has the same result.
best,
Anton
Sep 15, 2021 2:56 AM - edited Sep 15, 2021 7:24 AM
Hi @sjay,
done something similar recently with this code:
{% for content in contents %} {# fetch all blog posts #}
{% if loop.index >= 1 %} {# exclude first blog post #}
{# YOUR CONTENT GOES HERE #}
{% endif %}
{% endfor %}
best,
Anton
Sep 15, 2021 11:53 AM - edited Sep 15, 2021 11:55 AM
Wait, does this not mess with pagination? And is it different from using {% if not loop.first %}?
@dennisedson , cause if this works, I surely do not understand how 😂
Could you help me understand?
Sep 15, 2021 12:07 PM
Hi @Teun,
I would say that it depends how you're building your pagination.
I've wrote mine like this and it works flawlessly with the code above:
{% if not simple_list_page %}
<div class="row-fluid-wrapper">
<div class="row-fluid">
<div class="span12 col-12">
<div class="pagination">
{% if contents.total_page_count > 1 %}
<div class="blog-pagination">
{% set page_list = [-2, -1, 0, 1, 2] %}
{% if contents.total_page_count - current_page_num == 1 %}{% set offset = -1 %}
{% elif contents.total_page_count - current_page_num == 0 %}{% set offset = -2 %}
{% elif current_page_num == 2 %}{% set offset = 1 %}
{% elif current_page_num == 1 %}{% set offset = 2 %}
{% else %}{% set offset = 0 %}{% endif %}
<a class="pagination-prev {{ "blog-pagination__prev-link--disabled" if !last_page_num }}" href="{{ blog_page_link(last_page_num) }}">
<i class="fas fa-chevron-left"></i>
</a>
{% for page in page_list %}
{% set this_page = current_page_num + page + offset %}
{% if this_page > 0 and this_page <= contents.total_page_count %}
<a class="pagination-active {{ "me-blog-pagination__page--active" if this_page == current_page_num }}" href="{{ blog_page_link(this_page) }}">{{ this_page }}</a>
{% endif %}
{% endfor %}
<a class="pagination-next {{ "blog-pagination__next-link--disabled" if !next_page_num }}" href="{{ blog_page_link(current_page_num + 1) }}">
<i class="fas fa-chevron-right"></i>
</a>
</div>
{% endif %}
</div>
</div>
</div>
</div>
{% endif %}
when using {% if not loop.first %} could work too. To be honest never tried that. You could also write {% unless loop.first %}everything except the first post{% else %}first post{% endunless %}. Depends on how you want to build your logic but has the same result.
best,
Anton
Sep 16, 2021 10:07 AM
Quality conversation here 😍
Sep 16, 2021 10:15 AM
@dennisedson please check the slack channel for unqualified conversations 😄
Sep 15, 2021 12:12 PM
Sep 15, 2021 11:55 AM
Sep 14, 2021 8:36 AM
Hi @sjay ,
Use like this code it will help you show only 1 post and second loop show next 2
{% for content in contents %}
{% if loop.index == 1 %}
{{ content.name }}
{% endif %}
{% endfor %}
{% for content in contents %}
{% if loop.index > 2 %}
{{ content.name }}
{% endif %}
{% endfor %}
Hope this helps!
If we were able to answer your query, kindly help the community by marking it as a solution.
Thanks and Regard.
Sep 13, 2021 4:15 PM
@sjay Very curious to see how you ended up handling this!
Sep 13, 2021 5:08 AM
Hi @sjay ,
As the amount of posts shown per page is defined in the HubSpot blog settings, I did not find a workaround.
You could however, display an extra CTA (like the form CTA you have available) on the first page to make sure that you are not missing one card in your grid (so replace the first post with an CTA, but change its position).
If you only show this on the first page and exclude the first post with the if statement you allready have (or using if not loop.first), you should have a working blog listing.