1234567891011121314151617181920212223242526 |
- <?php
- const PAGINATOR_RADIUS = 5;
- function render_paginator($page_count, $current_page, callable $get_page_url) { ?>
- <p class="paginator"><?php
- if ($current_page > PAGINATOR_RADIUS) { ?>
- <a href="<?= call_user_func($get_page_url, 1) ?>">«</a><?php
- }
- for (
- $i = max(1, $current_page - PAGINATOR_RADIUS + 1);
- $i <= min($current_page + PAGINATOR_RADIUS - 1, $page_count);
- $i ++
- ) {
- if ($i == $current_page) {
- ?><a class="selected"><?= $i ?></a><?php
- }
- else {
- ?><a href="<?= call_user_func($get_page_url, $i) ?>"><?= $i ?></a><?php
- }
- }
- if ($current_page < $page_count - PAGINATOR_RADIUS) { ?>
- <a href="<?= call_user_func($get_page_url, $page_count) ?>">»</a><?php
- }
- ?>
- </p><?php
- }
|