1

How can I get the number of a current entry in a structure? In other words, I'm getting the total number of entries like so:

{% set count = craft.entries.section('projects').total() %}
<h1>{{ count }}</h1>

But, I'd like to be able to output the number of the current entry in the hierarchy, i.e. something like 1/10. How do I do that?

2

If you're using a for loop to output the entries you can make use of loop.index which will give you the current iteration of the loop (starting from 1) and loop.length which is the total number of items in the for loop.

So something along the lines of:

{% for entry in craft.entries.section('projects') %}
   {{ entry.title }} - {{ loop.index }} / {{ loop.length }}
{% endfor %}

Or, if you're on a single entry you can use this answer by Marion Newlevant.

2
  • I'm actually needing this in my _entry.html file, so it's out side of the the for loop. Any ideas on that? – Jesse Winton Jul 19 '16 at 16:45
  • Just updated my answer with a link to another answer you may find helpful. – Luke Pearce Jul 19 '16 at 16:57

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.