paginator.php 740 B

1234567891011121314151617181920212223242526
  1. <?php
  2. const PAGINATOR_RADIUS = 5;
  3. function render_paginator($page_count, $current_page, callable $get_page_url) { ?>
  4. <p class="paginator"><?php
  5. if ($current_page > PAGINATOR_RADIUS) { ?>
  6. <a href="<?= call_user_func($get_page_url, 1) ?>">&#171;</a><?php
  7. }
  8. for (
  9. $i = max(1, $current_page - PAGINATOR_RADIUS + 1);
  10. $i <= min($current_page + PAGINATOR_RADIUS - 1, $page_count);
  11. $i ++
  12. ) {
  13. if ($i == $current_page) {
  14. ?><a class="selected"><?= $i ?></a><?php
  15. }
  16. else {
  17. ?><a href="<?= call_user_func($get_page_url, $i) ?>"><?= $i ?></a><?php
  18. }
  19. }
  20. if ($current_page < $page_count - PAGINATOR_RADIUS) { ?>
  21. <a href="<?= call_user_func($get_page_url, $page_count) ?>">&#187;</a><?php
  22. }
  23. ?>
  24. </p><?php
  25. }