Exclude a current blog post from latest blog posts section

Hi, I’m looking for help regarding the issue I’m having with showing three recent blog posts below the article. I would like to remove the current article and skip to the next one.

Here’s the example - this is one of our latest blog posts:

And you can see that this same post is showing in the bottom of its own article under ‘Latest from our Blog’

We are using the Wokiee theme and the site in question is www.giftay.eu. How can we exclude the CURRENT POST from this section? Here is the liquid code for this section:

{%- assign item = section.settings -%}
{%- assign blog = blogs[item.blog] -%}
{%- assign grid = item.items | plus: 0 -%}

{%- capture image_size -%}600x{%- endcapture -%}

<div class="{% if item.top_offset == 'none' %}nomargin {% elsif item.top_offset == 'small' %}tt-offset-small {% endif %}container-indent {{ item.custom_classes }}">
  <div class="container{% if item.fullwidth %}-fluid{% endif %}">
    {%- if item.show_title -%}
    <div class="tt-block-title{% if item.title_to_left %} text-left{% endif %}{% if item.boxed_title and item.fullwidth %} container{% endif %}">
      <h2 class="tt-title" style="text-align: center;">
        {%- if item.use_title_as_link -%}<a href="{{ blog.url }}" class="title-hover-underline" title="{{ item.button_text }}">{{ item.text1 }}</a>
        {%- else -%}{{ item.text1 }}
        {%- endif -%}
      </h2>
      {% unless item.text2 == '' %}<div class="tt-description">{{ item.text2 }}</div>{% endunless %}
      {% unless item.default_carousel %}{% unless item.text3 == '' %}<p>{{ item.text3 }}</p>{% endunless %}{% endunless %}
    </div>{% endif %}
    <div class="tt-blog-thumb-list">
      <div class="row">
        {%- unless blog.empty? -%}
        
        {%- for article in blog.articles limit: item.limit -%}
        <div class="col-12 col-sm-6 col-md-6 col-lg-{{ grid }}">
          <div class="tt-blog-thumb respimgsize">
            {%- if article.image != blank -%}
            <div class="tt-img">
              <a href="{{ article.url }}">
                <img class="lazyload"
                     loading="lazy"
                     width="600"
                     height="314"
                     data-mainimage="{{ article.image | product_img_url: '100x100' | replace: '100x100', 'respimgsize' }}"
                     alt="{{ article.image.alt | escape }}"/>
              </a>
            </div>
            {%- endif -%}
            
            <div class="tt-title-description">
              <div class="tt-background"></div>
              {%- if article.tags.size > 0 and item.show_tags -%}<div class="tt-tag text-uppercase">
                {%- for tag in article.tags -%}
              		{%- assign a_url = tag | handle -%}{%- assign a_url = blog.url | append: '/tagged/' | append: a_url  -%}
              		{{ tag | link_to: a_url }}
              	{%- endfor -%}
              </div>{% endif %}
              <div class="tt-title{% if settings.block_titles_uppercase %} text-uppercase{% endif %}">
                <a href="{{ article.url }}">{{ article.title }}</a>
              </div>
              {%- if item.show_description -%}
              <p>{% if article.excerpt.size > 0 %}
                {%- if section.settings.truncate_excerpt -%}{{ article.excerpt | strip_html | truncatewords: section.settings.truncate, section.settings.truncate_last_symbols }}
                {%- else -%}{{ article.excerpt }}
                {%- endif -%}
                {%- else -%}{{ article.content | strip_html | truncatewords: section.settings.truncate, section.settings.truncate_last_symbols }}{%- endif -%}
              </p>
              {%- endif -%}
              <div class="tt-meta">
                {%- if section.settings.blog_show_author or section.settings.blog_show_date -%}
                <div class="tt-autor">
                  {% if item.blog_show_author %}{{ "blogs.general.author_by_html" | t: author: article.author }}{% endif %}
                  {% if item.blog_show_date %} {{ "blogs.general.on" | t }} {{ article.published_at | time_tag: format: 'date' }}{% endif %}
                </div>
                {%- endif -%}
                {%- if item.show_comment -%}
                {%- if article.comments.size > 0 -%}{%- assign comment_url = article.url | append: '#comments' -%}{%- else -%}{%- assign comment_url = article.url | append: '#addcomment' -%}{%- endif -%}
                <div class="tt-comments">
                  <a href="{{ comment_url }}"><i class="tt-icon icon-f-88"></i>{{ article.comments.size }}</a>
                </div>
                {%- endif -%}
              </div>
            </div>
          </div>
        </div>
        {%- endfor -%}
        
        {%- else -%}
        <span style="display: flex; justify-content: center;">This section doesn’t currently include any content. Add content to this section using the sidebar.</span>
        {%- endunless -%}
      </div>
    </div>
  </div>
</div>

Thanks in advance for any help!

Hello @Giftay ,

{% assign postLimit = 0 %}
{%- for article in blog.articles limit: item.limit -%}
  {%- if article.url != blog.url and postLimit < item.limit -%}
    YOUR STUFF
    {% assign postLimit = postLimit | plus: 1 %}
  {%- endif -%}
{%- endfor -%}

You can add this condition may be it’s helpful

Hi @iffikhan30 , thanks so much for helping out. Where should I put that code?

Should it go right below this line?

        {%- for article in blog.articles limit: item.limit -%}

Hey @iffikhan30 , I get this error when I try the code:

Liquid error (sections/index-section-blog line 25): comparison of Integer with String failedLiquid error (sections/index-section-blog line 25): comparison of Integer with String failedLiquid error (sections/index-section-blog line 25): comparison of Integer with String failed

And this is the line 25 from the code:

{%- if article.url != blog.url and postLimit < item.limit -%}

you assgin postlimit?

{%- for article in blog.articles limit: item.limit -%}

You already add this code for your article loop you add this If condition and then close

{%- if article.url != blog.url and postLimit < item.limit -%}
    YOUR STUFF
    {% assign postLimit = postLimit | plus: 1 %}
  {%- endif -%}

Yes @iffikhan30 , I did it this way:

{%- if article.url != blog.url and postLimit < item.limit -%}     
 {%- for article in blog.articles limit: item.limit -%}
        
          

            {%- if article.image != blank -%}
            

              
                
              
            

            {%- endif -%}
            
            
              

              {%- if article.tags.size > 0 and item.show_tags -%}
                {%- for tag in article.tags -%}
              		{%- assign a_url = tag | handle -%}{%- assign a_url = blog.url | append: '/tagged/' | append: a_url  -%}
              		{{ tag | link_to: a_url }}
              	{%- endfor -%}
              
{% endif %}
              
                {{ article.title }}
              

              {%- if item.show_description -%}
              

{% if article.excerpt.size > 0 %}
                {%- if section.settings.truncate_excerpt -%}{{ article.excerpt | strip_html | truncatewords: section.settings.truncate, section.settings.truncate_last_symbols }}
                {%- else -%}{{ article.excerpt }}
                {%- endif -%}
                {%- else -%}{{ article.content | strip_html | truncatewords: section.settings.truncate, section.settings.truncate_last_symbols }}{%- endif -%}
              

              {%- endif -%}
              
                {%- if section.settings.blog_show_author or section.settings.blog_show_date -%}
                

                  {% if item.blog_show_author %}{{ "blogs.general.author_by_html" | t: author: article.author }}{% endif %}
                  {% if item.blog_show_date %} {{ "blogs.general.on" | t }} {{ article.published_at | time_tag: format: 'date' }}{% endif %}
                

                {%- endif -%}
                {%- if item.show_comment -%}
                {%- if article.comments.size > 0 -%}{%- assign comment_url = article.url | append: '#comments' -%}{%- else -%}{%- assign comment_url = article.url | append: '#addcomment' -%}{%- endif -%}
                
                  {{ article.comments.size }}
                

                {%- endif -%}
              

            

          

        

     {% assign postLimit = postLimit | plus: 1 %}
   {%- endif -%}
 {%- endfor -%}

I’m not sure if I added the code properly, so if you could check it out… Thank you!

If condition Inside the for loop

Sorry @iffikhan30 , I did it the right way now, but it shows empty space now:

Let’s check your mail box.

Did you get this to work? Can you share the code?

Hello @Paulodezine

Try this

{% assign postLimit = 0 %}
{%- for article in blog.articles limit: item.limit -%}
  {%- if article.url != blog.url and postLimit < item.limit -%}
    YOUR STUFF
    {% assign postLimit = postLimit | plus: 1 %}
  {%- endif -%}
{%- endfor -%}

hi there, it doesnt work, the whole section is empty when I add this code.

Hello,

When i write your stuff you just call the title, then check