CMS Development

sjay
Member | Diamond Partner
Member | Diamond Partner

How to Exclude/Remove the first blog in Contents

SOLVE

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.

sjay_0-1631521369685.png

 

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

0 Upvotes
2 Accepted solutions
Anton
Solution
Recognized Expert | Diamond Partner
Recognized Expert | Diamond Partner

How to Exclude/Remove the first blog in Contents

SOLVE

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

Anton Bujanowski Signature

View solution in original post

Anton
Solution
Recognized Expert | Diamond Partner
Recognized Expert | Diamond Partner

How to Exclude/Remove the first blog in Contents

SOLVE

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

Anton Bujanowski Signature

View solution in original post

10 Replies 10
Anton
Solution
Recognized Expert | Diamond Partner
Recognized Expert | Diamond Partner

How to Exclude/Remove the first blog in Contents

SOLVE

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

Anton Bujanowski Signature
Teun
Recognized Expert | Diamond Partner
Recognized Expert | Diamond Partner

How to Exclude/Remove the first blog in Contents

SOLVE

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?



Learn more about HubSpot by following me on LinkedIn or YouTube

Did my answer solve your issue? Help the community by marking it as the solution.


0 Upvotes
Anton
Solution
Recognized Expert | Diamond Partner
Recognized Expert | Diamond Partner

How to Exclude/Remove the first blog in Contents

SOLVE

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

Anton Bujanowski Signature
dennisedson
HubSpot Product Team
HubSpot Product Team

How to Exclude/Remove the first blog in Contents

SOLVE

Quality conversation here 😍

0 Upvotes
Anton
Recognized Expert | Diamond Partner
Recognized Expert | Diamond Partner

How to Exclude/Remove the first blog in Contents

SOLVE

@dennisedson please check the slack channel for unqualified conversations 😄

Anton Bujanowski Signature
Teun
Recognized Expert | Diamond Partner
Recognized Expert | Diamond Partner

How to Exclude/Remove the first blog in Contents

SOLVE
That looks a lot like the code we use as well. I've had some issues with the posts per page and showing a nice grid, had to fill in the empty space with a CTA block.

I'll check for differences between your code and mine to see why yours is working.


Learn more about HubSpot by following me on LinkedIn or YouTube

Did my answer solve your issue? Help the community by marking it as the solution.


dennisedson
HubSpot Product Team
HubSpot Product Team

How to Exclude/Remove the first blog in Contents

SOLVE

@Teun , that is a good question!  I need to test if @Anton is messing with us 😜

webdew
Guide | Diamond Partner
Guide | Diamond Partner

How to Exclude/Remove the first blog in Contents

SOLVE

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.

0 Upvotes
Kevin-C
Recognized Expert | Partner
Recognized Expert | Partner

How to Exclude/Remove the first blog in Contents

SOLVE

@sjay Very curious to see how you ended up handling this!

Kevin Cornett - Sr. Solutions Architect @ BridgeRev
Teun
Recognized Expert | Diamond Partner
Recognized Expert | Diamond Partner

How to Exclude/Remove the first blog in Contents

SOLVE

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.



Learn more about HubSpot by following me on LinkedIn or YouTube

Did my answer solve your issue? Help the community by marking it as the solution.