CMS Development

RGrimsley
Contributor

Exclude Most Recent Blog Using HubL

SOLVE

Hey, folks!

 

I'm very new to the HubL world, so please forgive me if this is a very simple fix! I'm trying to create two containers to house our most recent blogs. One will be full-width and host the most recent blog, while the following will be three columns and host the previous 3 blogs. I'm having trouble creating an HTML + HubL function to ensure the most recent blog will be excluded from the three-column container. Can someone please help if they know how to fix this?

 

Here's the code I'm currently using:

<div class="listing-full-wrap">
<div class="content-wrapper">
<div class="row">
<section class="blog-index-wrap">
{% set rec_posts = blog_recent_posts(module.select_blog, 1) %}
{% for rec_post in rec_posts %}
<div class="post-items">

{% if rec_post.featured_image %}
<div class="summary-thumbnail-outer-container">
<a href="{{ rec_post.absolute_url }}" class="gallery-image-container">
<div class="summary-thumbnail img-wrapper">
<img src="{{ rec_post.featured_image }}" alt="{{ rec_post.name }}">
</div>
</a>
</div>
{% endif %}

<div class="summary-content gallery-meta-container">
<div class="summary-title">
<a href="{{ rec_post.absolute_url }}" class="summary-title-link">{{ rec_post.name }}</a>
</div>
<div class="summary-excerpt summary-excerpt-only">
<p>
{{ rec_post.post_list_content|truncatehtml(300)|striptags|safe }}
</p>
</div>
<div class="container--below-content">
<div class="summary-metadata--primary">
<time class="summary-metadata-item summary-metadata-item--date">{{ rec_post.publish_date_local_time.strftime('%b %d, %Y') }}</time>
</div>
</div>
</div>
</div>
{% endfor %}

</section>
</div>
</div>
</div>


<div class="listing-columns-wrap">
<div class="content-wrapper">
<div class="row">
<section class="blog-index-wrap">
{% set rec_posts = blog_recent_posts(module.select_blog, 3) %}
{% for rec_post in rec_posts %}

<div class="post-items">
{% if rec_post.featured_image %}
<div class="summary-thumbnail-outer-container">
<a href="{{ rec_post.absolute_url }}" class="gallery-image-container">
<div class="summary-thumbnail img-wrapper">
<img src="{{ rec_post.featured_image }}" alt="{{ rec_post.name }}">
</div>
</a>
</div>
{% endif %}

<div class="summary-content gallery-meta-container">
<div class="summary-title">
<a href="{{ rec_post.absolute_url }}" class="summary-title-link">{{ rec_post.name }}</a>
</div>
<div class="summary-excerpt summary-excerpt-only">
<p>
{{ rec_post.post_list_content|truncatehtml(300)|striptags|safe }}
</p>
</div>
<div class="container--below-content">
<div class="summary-metadata--primary">
<time class="summary-metadata-item summary-metadata-item--date">{{ rec_post.publish_date_local_time.strftime('%b %d, %Y') }}</time>
</div>
</div>
</div>
</div>
{% endfor %}

</section>
</div>
</div>
</div>

 

2 Accepted solutions
Brownstephen101
Solution
Top Contributor | Elite Partner
Top Contributor | Elite Partner

Exclude Most Recent Blog Using HubL

SOLVE

Change: 
{% set rec_posts = blog_recent_posts(module.select_blog, 3) %} 
to 
{% set rec_posts = blog_recent_posts(module.select_blog, 4) %}

Then in the {% for %} loop, wrap .post items with {% unless loop.index == 0 %}

This should skip your most recent blog and then loop through to the next 3

View solution in original post

Brownstephen101
Solution
Top Contributor | Elite Partner
Top Contributor | Elite Partner

Exclude Most Recent Blog Using HubL

SOLVE

Sorry, I forgot that loop.index actually starts at 1. So just update it to be {% unless loop.index == 1 %} and it should work.

View solution in original post

4 Replies 4
Brownstephen101
Solution
Top Contributor | Elite Partner
Top Contributor | Elite Partner

Exclude Most Recent Blog Using HubL

SOLVE

Change: 
{% set rec_posts = blog_recent_posts(module.select_blog, 3) %} 
to 
{% set rec_posts = blog_recent_posts(module.select_blog, 4) %}

Then in the {% for %} loop, wrap .post items with {% unless loop.index == 0 %}

This should skip your most recent blog and then loop through to the next 3

RGrimsley
Contributor

Exclude Most Recent Blog Using HubL

SOLVE

Thank you so much for this edit! I made the change to this, but it's still rendering my most recent blog:

 

<div class="listing-columns-wrap">
<div class="content-wrapper">
<div class="row">
<section class="blog-index-wrap">
{% set rec_posts = blog_recent_posts(module.select_blog, 4) %}
{% for rec_post in rec_posts %}
{% unless loop.index == 0 %}

<div class="post-items">
{% if rec_post.featured_image %}
<div class="summary-thumbnail-outer-container">
<a href="{{ rec_post.absolute_url }}" class="gallery-image-container">
<div class="summary-thumbnail img-wrapper">
<img src="{{ rec_post.featured_image }}" alt="{{ rec_post.name }}">
</div>
</a>
</div>
{% endif %}
{% endunless %}

 

Did I put this in the right place?

Brownstephen101
Solution
Top Contributor | Elite Partner
Top Contributor | Elite Partner

Exclude Most Recent Blog Using HubL

SOLVE

Sorry, I forgot that loop.index actually starts at 1. So just update it to be {% unless loop.index == 1 %} and it should work.

RGrimsley
Contributor

Exclude Most Recent Blog Using HubL

SOLVE

THAT WORKED!! Thank you so much!!!