related_blog_posts based on updated_time

How can I retrieve the latest three articles based on their update date and time?

{% macro related_posts(post, count, total) %}
{% if count == 1 %}
<ul>
{% endif %}

<li> // content // </li>

{% if count == total %}
</ul>
{% endif %}
{% endmacro %}

{% related_blog_posts
limit=3,
no_wrapper=True,
post_formatter=“related_posts”
%}

related_blog_posts is for getting posts related to the content of the current page. To get specific posts you would want to use the blog_recent_posts function instead. The function itself gets the most recently published, but you can use the |sort filter to instead sort it by updated date.
A simple example for getting the most recently updated posts:

// set variable to hold posts, max of 250 is allowed
{% set posts = blog_recent_posts("default", 250) %}

// loop through posts, sorted by 'updated' attribute
{% for post in posts|sort(true, false, 'updated') %}
 // only show the first 3 posts
 {% if loop.index <= 3 %}
 // content you want to display
 <p>{{ post.name }} {{ format_datetime(post.updated, "MMM d, YYYY") }}</p>
 {% endif %}
{% endfor %}

Thank you!!

If I want to output the three latest posts on a post page, there is a possibility of overlap with the currently displayed post page using the given example.

Is there a way to avoid this overlap?

Or, can I sort using parameters or conditions with the following statement?

{% macro related_posts(post, count, total) %}
{% if count == 1 %}
<ul>
{% endif %}

<li> // content // </li>

{% if count == total %}
</ul>
{% endif %}
{% endmacro %}

{% related_blog_posts
limit=3,
no_wrapper=True,
post_formatter=“related_posts”
%}

We can just add a check to see if the ID of the current content matches any of our three posts’ ID and, if so, skip it and show the next post instead.

// macro for our displayed content
{% macro postFormatter(post) %}
 <p>{{ post.name }} {{ format_datetime(post.updated, "MMM d, YYYY") }}</p>
{% endmacro %}

{% set posts = blog_recent_posts("default", 250) %}
// variable that we'll update to let us know if current post exists in loop
{% set check = {currentPost: false} %}

{% for post in posts|sort(true, false, 'updated') %}
 {% if loop.index <= 3 %}
 // check if post ID matches current content's ID
 {% if post.id == content.id %}
 // if it does, update our check variable to true
 {% do check.update({'currentPost': true}) %}
 {% else %}
 // if it doesn't, display post content
 {{ postFormatter(post) }}
 {% endif %}
 {% endif %}

 // if our check variable is true, show the 4th post in the loop
 {% if loop.index == 4 && check.currentPost %}
 {{ postFormatter(post) }}
 {% endif %}
{% endfor %}

Sometimes the current post ID doesn’t come through in the page editor, so you may see the current post listed there, but when viewing a preview or published page the current post in the list will be replaced with a different post.