includes/modules/pagination.php

<?php
/*
|--------------------------------------------------------------------------
| Top pages pagination
|--------------------------------------------------------------------------
|
| Renders a compact "1 ... 4 5 [6] 7 8 ... 42" style page list: always
| shows first/last page plus up to 2 pages on each side of the current
| one, with a "…" gap filled in when the window doesn't reach an edge.
| $topPageNum, $topPerPage, $topLastPage and the period vars ($view, $day,
| $week, $month, $year, $currentSite) are set by the including dashboard view.
|
*/
$baseParams = dashboardPaginationParams(
    $view,
    $day,
    $week,
    $month,
    $year,
    ['site' => $currentSite]
);
?>

<nav class="pagination">
    <?php if ($topPageNum > 1): ?>
        <a href="?<?= h($baseParams) ?>&per=<?= $topPerPage ?>&tp=<?= $topPageNum - 1 ?>"><?= icon('previous') ?> <?= h(t('ui.pagination.previous')) ?></a>
    <?php endif; ?>

    <?php
    $pages = range(
        max(1, $topPageNum - 2),
        min($topLastPage, $topPageNum + 2)
    );
    ?>

    <?php if (!in_array(1, $pages, true)): ?>
        <a href="?<?= h($baseParams) ?>&per=<?= $topPerPage ?>&tp=1">1</a>
        <?php if ($pages[0] > 2): ?><span>…</span><?php endif; ?>
    <?php endif; ?>

    <?php foreach ($pages as $p): ?>
        <?php if ($p === $topPageNum): ?>
            <strong><?= h($p) ?></strong>
        <?php else: ?>
            <a href="?<?= h($baseParams) ?>&per=<?= $topPerPage ?>&tp=<?= $p ?>"><?= h($p) ?></a>
        <?php endif; ?>
    <?php endforeach; ?>

    <?php if (!in_array($topLastPage, $pages, true)): ?>
        <?php if (end($pages) < $topLastPage - 1): ?><span>…</span><?php endif; ?>
        <a href="?<?= h($baseParams) ?>&per=<?= $topPerPage ?>&tp=<?= $topLastPage ?>"><?= h($topLastPage) ?></a>
    <?php endif; ?>

    <?php if ($topPageNum < $topLastPage): ?>
        <a href="?<?= h($baseParams) ?>&per=<?= $topPerPage ?>&tp=<?= $topPageNum + 1 ?>"><?= h(t('ui.pagination.next')) ?> <?= icon('next') ?></a>
    <?php endif; ?>
</nav>

Contribute