0

I have the following channel entry tag:

{exp:channel:entries channel="designs" orderby="title" sort="asc" limit="8" paginate="bottom" dynamic="no"}

{!--output--}

{paginate}
    <div class="pagination clearfix">
        <ul>
            <li class="pagination-button">
            {if previous_page}<a href="{auto_path}">{/if}
            <i class="icon-angle-left"></i>
            {if previous_page}</a>{/if}
            </li>
            <li><p>{current_page} of {total_pages}</p></li>
            <li class="pagination-button">
            {if next_page}<a href="{auto_path}">{/if}
            <i class="icon-angle-right"></i>
            {if next_page}</a>{/if}
            </li>
        </ul>
    </div>
{/paginate}

{/exp:channel:entries}

Now that pagination displays the current and total pages, but instead I want it to show the current entries range and total entries, like this:

1 - 8 of 26 results for page one

9 - 16 of 26 results for page two

and so on.

I assembled this string:

{count} to {absolute_count} of {absolute_results} results

but I obviously can't just put it in the entry tag as it would parse for each entry. Moreover, {count} references the currently displayed items (ie. {count} will always be 1-8). I would have to do some sort of calculation to find the first count of the page. I assume an addon like Math would be suitable.

So to get the correct last count (ie. 8, 16, 24 etc.) the string should only be parsed on the final entry for a given page. What sort of condition could I use to ensure it only parses for the last entry?

1

I'm not a big proponent of PHP in templates, but this is a case where it might be your best option. (You could roll this code into a simple plugin as well, which accepted the three required variables at the top as parameters.)

Enable PHP on output, and add this code:

{paginate}
    $per_page = 8;
    $current_page = '{current_page}';
    $total_entries = '{absolute_results}';

    $end = $per_page * $current_page;
    $start = ($end - $per_page) + 1;
    $end = ($end > $total_entries) ? $total_entries : $end;

    echo $start.' - '.$end.' of '.$total_entries;
{/paginate}
| 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.