Display only Blog authors that have at least one live post
SOLVE
I have some HubL code that displays all authors but I need help how to display only blog authors that have at least one active blog post so blog authors do not have active blog post will not display. Here is my current HubL code:
{% set my_topics = blog_authors('default', 250) %}
<div class="contribute_wrap">
<h3>Contributors</h3>
<ul class="contribute_list">
{% for item in my_topics %}
<li><a href="{{ blog_author_url(group.id, item.slug) }}">{{ item }}</a></li>
{% endfor %}
</ul>
Display only Blog authors that have at least one live post
SOLVE
Hi Chris, I took a look at this and have added in some logic that will prevent an author from being included, if they have no published posts:
{% set my_topics = blog_authors(group.id, 250) %}
<div class="contribute_wrap">
<h3>Contributors</h3>
<p>{{ my_topics }}</p>
<ul class="contribute_list">
{% for item in my_topics %}
{% set posts = blog_recent_author_posts(group.id, item.slug, 5 ) %} {# this function returns a sequence of the author's recent posts #}
{% if posts %} {# this if statement will evaluate to false if the author has no published posts #}
<li><a href="{{ blog_author_url(group.id, item.slug) }}">{{ item }}</a></li>
{% endif %}
{% endfor %}
</ul>
Hope this helps! Feel free to DM me if you want to dig into this.
Display only Blog authors that have at least one live post
SOLVE
Hi Chris, I took a look at this and have added in some logic that will prevent an author from being included, if they have no published posts:
{% set my_topics = blog_authors(group.id, 250) %}
<div class="contribute_wrap">
<h3>Contributors</h3>
<p>{{ my_topics }}</p>
<ul class="contribute_list">
{% for item in my_topics %}
{% set posts = blog_recent_author_posts(group.id, item.slug, 5 ) %} {# this function returns a sequence of the author's recent posts #}
{% if posts %} {# this if statement will evaluate to false if the author has no published posts #}
<li><a href="{{ blog_author_url(group.id, item.slug) }}">{{ item }}</a></li>
{% endif %}
{% endfor %}
</ul>
Hope this helps! Feel free to DM me if you want to dig into this.