Truncating authors

In the code below, I want to add suffix=" & Others" only when there are more than two authors assigned to a post. How do I do that?

  {{#if single_author}}
    <span class="post-info__authors">{{authors limit="1" separator=", "}}</span>
    <span class="post-info__authors">{{authors limit="2" separator=" and "}}</span>

As it stands, the code above outputs:

  • One author if there is a single author assigned
  • Two authors with “and” separating them if two authors are assigned

Theme: Maali

Hi @Rhys!

After customization, this code should work for you:

{{#has author="count:1"}}
{{else has author="count:2"}}
{{authors separator=" and "}}
{{else has author="count:>2"}}
{{authors limit="2" separator=", "}} and others

Hi! Thanks for providing that. It works, but the CSS changes and I’m not sure where to tweak it to match the original.


Using your code:

Based on your first example, it could look like this:

{{#has author="count:1"}}
<span class="post-info__authors">{{authors}}</span>
{{else has author="count:2"}}
<span class="post-info__authors">{{authors separator=" and "}}</span>
{{else has author="count:>2"}}
<span class="post-info__authors">{{authors limit="2" separator=", "}} and others</span>

Thanks so much for this!

1 Like