Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1.  
  2. public function getPagination($current_page = 1, $count_pages , $start = 1)
  3. {
  4.  
  5. global $config;
  6.  
  7. $max_pages_list = 7; // сколько номеров страниц показывать
  8. $pagination = "";
  9.  
  10. $smarty = new Smarty();
  11.  
  12. $smarty->template_dir = $config['path']['root'].'templates/newdesign/';
  13. $smarty->compile_dir = $config['path']['root'].'tmp/';
  14.  
  15. // логика пагинации
  16.  
  17. $first_page = $current_page - (int) ($max_pages_list / 2);
  18.  
  19. $last_page = $first_page + $max_pages_list - 1;
  20.  
  21. if ($last_page > $count_pages)
  22. $last_page = $count_pages;
  23.  
  24. if ( $first_page <= 1 )
  25. $first_page = 1;
  26. else {
  27. if ( $count_pages - $first_page < $max_pages_list ){
  28. $first_page = $count_pages - $max_pages_list + 1;
  29. if ( $first_page <= 1 )
  30. $first_page = 1;
  31. }
  32. }
  33. $page_last = str_replace("&ajax=".$current_page,"&page=".($current_page-1), $_SERVER['REQUEST_URI']); //текущая страница и заменяем слово ajax на page
  34. $page_next = str_replace("&ajax=".$current_page,"&page=".($current_page+1), $_SERVER['REQUEST_URI']); //текущая страница и заменяем слово ajax на page
  35.  
  36. if ( $first_page > 3 ){
  37. $pagination .= '<a href="' . $page_last . '">&laquo;</a>';
  38. $pagination .= '<a href="">' . $start . '</a>';
  39. $pagination .= '<a href="">' . 2 . '</a>';
  40. $pagination .= '<a>...</a>';
  41. }
  42.  
  43. for ( $i = $first_page; $i <= $last_page; $i++ ){
  44.  
  45. $activeClass = $i <= $current_page ? "active" : "";
  46.  
  47. $page = str_replace("&ajax=".$current_page,"&page=".$i, $_SERVER['REQUEST_URI']); //текущая страница и заменяем слово ajax на page
  48.  
  49. $pagination .= '<a class="'. $activeClass .'" href="' . $page . '">' . $i . '</a>';
  50.  
  51. }
  52.  
  53. if ( $last_page < $count_pages-1 ) {
  54. $pagination .= '<a>...</a>';
  55. $pagination .= '<a href="' . $page . '">' . $count_pages . '</a>';
  56.  
  57. $pagination .= '<a href="' . $page_next . '">&raquo;</a>';
  58. }
  59. // передача данных в шаблон
  60. $smarty->assign('pagination', $pagination);
  61.  
  62. // вывод шаблона пагинации
  63. return $smarty->fetch('include/common/pagination.tmpl');
  64.  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement