Only Show Primary Author in #foreach posts

Hi,

I am trying to only show the primary author when using {{#foreach posts}} on my homepage.

This is what I have so far:

{{#foreach posts visibility="all" limit="1"}}
{{#if @first}}
<div class="col-md-6">
  <article class="card featured-card {{post_class}} bg-dark text-white border-0">
    {{#if feature_image}}
    <div class="card-image" style="background-image: url('{{img_url feature_image}}')"></div>
    {{/if}}
    <div class="card-img-overlay">
      {{#if primary_tag}}
      {{#primary_tag}}
      <div class="post-tags">
        <a href="{{url}}" class="badge badge-primary">{{name}}</a>
      </div>
      {{/primary_tag}}
      {{/if}}
      <div class="post-content">
        <h1 class="post-title"><a href="{{url}}">{{title}}</a></h1>
        <p class="post-description">
          {{excerpt words="30"}}
        </p>
        {{#foreach authors}}
        <a href="{{author}}" class="author-info pt-5">
          <div class="d-flex align-content-start flex-wrap">
            {{#if profile_image}}
            <div class="author-image background"
              style="background-image: url('{{img_url profile_image}}')">
            </div>
            {{else}}
            <div class="author-image background"
              style="background-image: url('{{@site.icon}}')">
            </div>
            {{/if}}
            <div class="author-meta">
              <p class="text-white">{{name}}</p>
              <span class="text-light"><time datetime="{{date format="YYYY-MM-DD"}}">{{date format="D MMM YYYY"}}</time></span>
            </div>
          </div>
        </a>
        {{/foreach}}
      </div>
    </div>
  </article>
</div>
{{/if}}
{{/foreach}}

Any help would be greatly appreciated.

Solution

{{#foreach authors limit="1"}}

1 Like

I think the best solution would be to just call the first author.

{{#primary_author}}
{{/primary_author}}

You can see an example in my Mapache theme.

1 Like