1

I have a channel which has multiple entries in, I'm trying to output the current entry number, for example "1 out of 20 posts"

Currently this is what I am working with:

{% set total = craft.entries().section('spotlights').count() %}
{% set params = {section: 'spotlights', order: 'postDate desc', limit: null} %}
{% set entry_prev = entry.getPrev(params) %}
{% set entry_next = entry.getNext(params) %}

<section class="page-nav-wrapper">
  <div class="container">
    <div class="page-nav">
      {% if entry_prev %}
      <div class="previous-page">
        <a href="{{entry_prev.url}}">Previous</a>
      </div>
      {% else %}
      <div class="previous-page">
        <a class="disabled">Previous</a>
      </div>
      {% endif %}
      <div class="entry-count">ENTRY NUMBER HERE of {{ total }}</div>
      {% if entry_next %}
      <div class="next-page">
        <a href="{{entry_next.url}}">Next</a>
      </div>
      {% else %}
      <div class="next-page">
        <a class="disabled">Next</a>
      </div>
      {% endif %}
    </div>
  </div>
</section>

I have my next and previous links working as well as the total entries in the section, I just can't work out how to get the current entry in the section. Any help would be appreciated.

I have tried a few different solutions on here but they all seem to be outdated.

Thanks.

1

I don't know if this is the best solution or if it will even work, but this would be my first try.

{% for spotlight in craft.entries().section('spotlights').all() %}
  {# Check to see if the title of the "spotlight" matches the current entry's title #}
  {% if spotlight.title == entry.title %}
    <div class="entry-count">{{ loop.index }} of {{ total }}</div>
  {% endif %}
{% endfor %}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.