Display only Blog authors that have at least one live post


#1

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>

#2

And the sort in Descending based on “totalPosts”


#3

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.


#4

Thank you James, this worked perfectly!!!


#5

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?


#7

Hey, @Thomas_Bodocean.

I can take a look. Would you share links to the module and the template you're using it in?


#8

I changed the module into something completely else but i used blog_authors('default', 250) with a for loop. I now use HubDB to make it happen. The Database contains exactly, what the Authors Page contains but now i can use a "{% for row in hubdb_table_rows(x) %}".

It is a trashy workaround but this works so far. It would be amazing if there is a way to access the authors data from everywhere using HubL.

I had a different approach found in this article but this wasn't ideal either (I failed). Also using an API key for the public is not a smart decision.