Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. public function getPagination($current = 1, $totalPages, $start = 1)
  2. {
  3.  
  4. global $config;
  5.  
  6. $smarty = new Smarty();
  7.  
  8. $smarty->template_dir = $config['path']['root'].'templates/newdesign/';
  9. $smarty->compile_dir = $config['path']['root'].'tmp/';
  10.  
  11.  
  12. // логика пагинации
  13.  
  14. $pagination = '<a href="#">&laquo;</a>';
  15.  
  16. for($i = 1; $i <= $totalPages; $i++)
  17. {
  18.  
  19. $activeClass = $i <= $current ? "active" : "";
  20.  
  21. $page = str_replace("&ajax=".$current,"&page=".$i, $_SERVER['REQUEST_URI']); //текущая страница и заменяем слово ajax на page
  22.  
  23. if($i <= $current+3)
  24. {
  25. $pagination .= '<a class="'. $activeClass .'" href="' . $page . '">' . $i . '</a>';
  26. } elseif ($i > $totalPages-3) {
  27. if($i == $totalPages-2)
  28. $pagination .= "<a href='#'>....</a>";
  29.  
  30. $pagination .= '<a href="' . $page . '">' . $i . '</a>';
  31.  
  32. }
  33. }
  34. $pagination .= '<a href="#">&raquo;</a>';
  35.  
  36.  
  37.  
  38.  
  39. // передача данных в шаблон
  40. $smarty->assign('pagination', $pagination);
  41.  
  42. // вывод шаблона пагинации
  43. return $smarty->fetch('include/common/pagination.tmpl');
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement