<p>You could do something like this:</p>

<pre class="lang-twig prettyprint-override"><code>{# Fetch entries + authors and group by author id #}
{% set entriesByAuthors = craft
    .entries()
    .section('itbuzz')
    .limit(null)
    .with('author')
    .all() | group(e =&gt; e.author.id) %}

{# Build an array with authorId and entry count for each that we can sort them #}
{% set leaderBoard = [] %}
{% for author, entries in entriesByAuthors  %}
    {% set leaderBoard = leaderBoard | merge([{'author' : author, 'count' : entries | length}]) %}
{% endfor %}

{# Build an array of user ids only sorted by entry count and extract the top 8 #}
{% set authorIds = [] %}
{% for result in leaderBoard | multisort(e =&gt; e.count, direction=SORT_DESC) | slice(0,8) %}
    {% set authorIds = authorIds | merge([result.author]) %}
{% endfor %}

{# Fetch users based on our sorted and sliced array of ids #}
{% for author in craft.users().id(authorIds).all() %}
    {{ author.firstName }} - {{ author.lastName }}&lt;br&gt;
{% endfor %}
</code></pre>

CC BY-SA 4.0
2020-03-04T14:36:26.753Z
Oli, this works perfectly, thank you.  I"m not sure what's going on in with `.with(author)` and the `|group` filter. Could you explain that a little for me. Thank you.
CreateSean
CC BY-SA 4.0
2020-03-04T09:47:21.007Z
2020-03-04T09:47:21.007Z
Oli
<p>Maybe a good excuse to use the spaceship operator (<code>&lt;=&gt;</code>)... Combined with the <code>group</code> filter, this seems to work for me:</p>

<pre><code>{% set groupedEntries = craft.entries.section('itbuzz').all()|group('author') %}

{% for author, entries in groupedEntries|sort((a, b) =&gt; a|length &lt;=&gt; b|length)|reverse|slice(0,8) %}
    &lt;h3&gt;{{ author }}&lt;/h3&gt;
    {# optionally output their entries too... #}
    &lt;ul&gt;
        {% for entry in entries %}
            &lt;li&gt;{{ entry.title }}&lt;/li&gt;
        {% endfor %}
    &lt;/ul&gt;
{% endfor %}
</code></pre>

CC BY-SA 4.0
2020-03-04T10:05:27.133Z
Thought of that but the simple fact of grouping means you loose your `user` object and Sean seems to need to access `author.stuff` ¯\_(ツ)_/¯
Oli
CC BY-SA 4.0
2020-03-04T10:06:33.800Z
Ah ha good point yerp.
James Smith
CC BY-SA 4.0
2020-03-04T14:38:13.550Z
That sort filter - wow, I would never have thought of that.
CreateSean
CC BY-SA 4.0
2020-03-04T10:00:15.277Z
2020-03-04T10:00:15.277Z
James Smith
<p>I need to output a list of channel authors. There are about 40 authors but I want the 8 authors with the most entries. Not sure how to achieve this.</p>

<p>What I have so far:</p>

<pre><code>    {# get all the itbuzz entries #}
    {% set allEntries = craft.entries.section('itbuzz').all() %}
    {# get all the authors #}
    {% set authors = craft.users.group('itBuzzAuthor').limit(8).all() %}

    &lt;ul class="flex flex-row flex-wrap"&gt;
      {% for author in authors %}
        &lt;li class="inline-block mb-4 mr-4 text-sm text-center"&gt;
          &lt;img src="{{ craft.gravatar.url( author.email ) }}" alt=""&gt;
          &lt;a href="#" class="text-blackBrand"&gt;{{ author.firstName }}&lt;br&gt;{{ author.lastName }}&lt;/a&gt;
        &lt;/li&gt;
      {% endfor %}
    &lt;/ul&gt;
</code></pre>

<p>All this does is output the first 8 authors, it's not finding the 8 with the most entries.</p>

<templating><users><author>
List authors on front end by total number of entries
# List authors on front end by total number of entries

(Asked by: username_0 on 2020-03-02)

I need to output a list of channel authors. There are about 40 authors but I want the 8 authors with the most entries. Not sure how to achieve this.
What I have so far:
    {# get all the itbuzz entries #}
    {% set allEntries = craft.entries.section('itbuzz').all() %}
    {# get all the authors #}
    {% set authors = craft.users.group('itBuzzAuthor').limit(8).all() %}

    
      {% for author in authors %}
        
          
          {{ author.firstName }}{{ author.lastName }}
        
      {% endfor %}
    

All this does is output the first 8 authors, it's not finding the 8 with the most entries.

**Tags:** templating, users, author

---

## 2 answers

### Answer by username_1 on 2020-03-04. Score: 2 | Accepted answer

You could do something like this:
{# Fetch entries + authors and group by author id #}
{% set entriesByAuthors = craft
    .entries()
    .section('itbuzz')
    .limit(null)
    .with('author')
    .all() | group(e => e.author.id) %}

{# Build an array with authorId and entry count for each that we can sort them #}
{% set leaderBoard = [] %}
{% for author, entries in entriesByAuthors  %}
    {% set leaderBoard = leaderBoard | merge([{'author' : author, 'count' : entries | length}]) %}
{% endfor %}

{# Build an array of user ids only sorted by entry count and extract the top 8 #}
{% set authorIds = [] %}
{% for result in leaderBoard | multisort(e => e.count, direction=SORT_DESC) | slice(0,8) %}
    {% set authorIds = authorIds | merge([result.author]) %}
{% endfor %}

{# Fetch users based on our sorted and sliced array of ids #}
{% for author in craft.users().id(authorIds).all() %}
    {{ author.firstName }} - {{ author.lastName }}
{% endfor %}

> **Comments:**
> **username_0**: Oli, this works perfectly, thank you.  I"m not sure what's going on in with `.with(author)` and the `|group` filter. Could you explain that a little for me. Thank you.  

---

### Answer by username_2 on 2020-03-04. Score: 1

Maybe a good excuse to use the spaceship operator (<=>)... Combined with the group filter, this seems to work for me:
{% set groupedEntries = craft.entries.section('itbuzz').all()|group('author') %}

{% for author, entries in groupedEntries|sort((a, b) => a|length <=> b|length)|reverse|slice(0,8) %}
    {{ author }}
    {# optionally output their entries too... #}
    
        {% for entry in entries %}
            {{ entry.title }}
        {% endfor %}
    
{% endfor %}

> **Comments:**
> **username_1**: Thought of that but the simple fact of grouping means you loose your `user` object and Sean seems to need to access `author.stuff` ¯\_(ツ)_/¯  
> **username_2**: Ah ha good point yerp.  
> **username_0**: That sort filter - wow, I would never have thought of that.  

---

