Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function getPagination($current_page = 1, $count_pages , $start = 1)
- {
- global $config;
- $max_pages_list = 7; // сколько номеров страниц показывать
- $pagination = "";
- $smarty = new Smarty();
- $smarty->template_dir = $config['path']['root'].'templates/newdesign/';
- $smarty->compile_dir = $config['path']['root'].'tmp/';
- // логика пагинации
- $first_page = $current_page - (int) ($max_pages_list / 2);
- $last_page = $first_page + $max_pages_list - 1;
- if ($last_page > $count_pages)
- $last_page = $count_pages;
- if ( $first_page <= 1 )
- $first_page = 1;
- else {
- if ( $count_pages - $first_page < $max_pages_list ){
- $first_page = $count_pages - $max_pages_list + 1;
- if ( $first_page <= 1 )
- $first_page = 1;
- }
- }
- $page_last = str_replace("&ajax=".$current_page,"&page=".($current_page-1), $_SERVER['REQUEST_URI']); //текущая страница и заменяем слово ajax на page
- $page_next = str_replace("&ajax=".$current_page,"&page=".($current_page+1), $_SERVER['REQUEST_URI']); //текущая страница и заменяем слово ajax на page
- if ( $first_page > 3 ){
- $pagination .= '<a href="' . $page_last . '">«</a>';
- $pagination .= '<a href="">' . $start . '</a>';
- $pagination .= '<a href="">' . 2 . '</a>';
- $pagination .= '<a>...</a>';
- }
- for ( $i = $first_page; $i <= $last_page; $i++ ){
- $activeClass = $i <= $current_page ? "active" : "";
- $page = str_replace("&ajax=".$current_page,"&page=".$i, $_SERVER['REQUEST_URI']); //текущая страница и заменяем слово ajax на page
- $pagination .= '<a class="'. $activeClass .'" href="' . $page . '">' . $i . '</a>';
- }
- if ( $last_page < $count_pages-1 ) {
- $pagination .= '<a>...</a>';
- $pagination .= '<a href="' . $page . '">' . $count_pages . '</a>';
- $pagination .= '<a href="' . $page_next . '">»</a>';
- }
- // передача данных в шаблон
- $smarty->assign('pagination', $pagination);
- // вывод шаблона пагинации
- return $smarty->fetch('include/common/pagination.tmpl');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement