I am struggling to get the correct syntax to display a single entry for each author who has a post. I am able to print an array with all post authors, but it duplicates authors in my list and that just isnt cool. I am trying to use the “unique” filter, but i must not be selecting the correct attribute?
here is the code:
{% set blog = blog_recent_posts('6035003896') %}
{% set news = blog_recent_posts('5989572231') %}
{% set contents = (news + blog)|unique('blog_author.display_name') %}
<ul>
{% for content in contents %}
<li>{{ content.blog_author.display_name }}</li>
{% endfor %}
</ul>
@dennisedson - Maybe someone else has a creative way to solve this feature but I don’t see it. I believe the blog_recent_posts stores a reference to the blog object, not the object itself. I think that happens once it enters the for loop.
And since for loops are Scoped, good luck attempting to store “used authors” outside of the for loop in an array and checking against them.
I know this post is years old but I came across it today as a suggestion from an unrelated post. And as it turns out I think I have a solution that works for this
I did this for a client last year. It was convoluted to figure out and there may be some simpler way I’m overlooking. But I’ll post it none the less for posterity in case anyone else comes across this post.
@dennisedson I hope you found a solution before now!
{% set my_authors = blog_authors(34471392197, 250) %}
{% set rec_posts = blog_recent_posts(34471392197, 200) %}
{% set recent_author_array = []%}
{% for rec_post in rec_posts %}
{% unless rec_post.blog_post_author.slug in recent_author_array %}
{# Append to array if it is not #}
{% do recent_author_array.append( rec_post.blog_post_author.slug ) %}
{% endunless %}
{% endfor %}
<ul>
{% for author in my_authors %}
{% if author.slug in recent_author_array %}
{% for rec_post in rec_posts|selectattr('blog_post_author.slug', 'equalto',author.slug) %}
{% if loop.index == 1 %}
<li>{{ author.display_name }} <a href="{{ rec_post.absolute_url }}">latest article</a></li>
{% endif %}
{% endfor %}
{% endif %}
{% endfor %}
</ul>