2

I have this loop

{% paginate craft.entries.section('sermons').limit('10') as pageInfo, entries %}

        {% for sermon in entries %}
        ...
        {{ loop.revindex }}
        ...
        {% endfor %}

That outputs a count from 10 to 1 - however, there's more entries than just the 10.

How can I output the count of what would be absolute total results?

4

You already pass the array keys into the loop as a variable pageInfo. There's a couple of properties you can access from it, see the Craft docs:

Templating Reference → {% paginate %}

Of interest for you is probably these:

pageInfo.total – The total number of elements across all pages
pageInfo.currentPage – The current page number.

It looks like there's no property for the "current element number" and you need to do some math to output it:

{% paginate craft.entries.limit(10) as pageInfo, pageEntries %}    
    {% for entry in pageEntries %}

        {% set index = (pageInfo.currentPage - 1) * 10 + loop.index0 %}

        {{ pageInfo.total - index }} of
        {{ pageInfo.total }}

    {% endfor %}
{% endpaginate %}
| improve this answer | |
  • No dice on the 2nd page of paginated entries with that update. 1st entry on that page shows 211 when it should be 171 – Steven Grant Feb 11 '16 at 13:35
  • Did you adjust the numbers? I tested the solution and it worked on my install... – carlcs Feb 11 '16 at 13:37
  • 1
    Doh! My limit was different after trying something else – Steven Grant Feb 11 '16 at 13:42
-1
{% set sermons = craft.entries.section('sermons').limit(null) %}

{{ sermons|length }}

By default, the .find() method, which is what gets called when you call craft.entries automatically gets limited to 100. Get round that by using .limit(null)

| improve this answer | |
  • I don't want to display them all though, they need pagination. I have 221 entries so I want to count each down from 221 to 1 – Steven Grant Feb 11 '16 at 11:25

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.