APIs & Integrations

cabplanalp
Participant

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>
0 Upvotes
1 Accepted solution
jamesCutler
Solution
HubSpot Product Team
HubSpot Product Team

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.

View solution in original post

0 Upvotes
4 Replies 4
Bodocean
Member

Display only Blog authors that have at least one live post

SOLVE

Did something change on this code? - I have a similar Problem and tried this code. It only displays the last Author in my Authors List.

What has to be done to have a list of all Authors in a Blog? - Does the Module have to be posted inside the Blog?

0 Upvotes
cabplanalp
Participant

Display only Blog authors that have at least one live post

SOLVE

Thank you James, this worked perfectly!!!

0 Upvotes
jamesCutler
Solution
HubSpot Product Team
HubSpot Product Team

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.

0 Upvotes
cabplanalp
Participant

Display only Blog authors that have at least one live post

SOLVE

And the sort in Descending based on “totalPosts”

0 Upvotes