/ Published in: PHP
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
'paging_range' => 2, 'first_last_link' => true, 'first_character' => '<em>«</em> First', 'last_character' => 'Last <em>»</em>', ); $options = array_merge_replace($default_options, $options); $record_start = $page > 1 ? ($per_page * ($page-1)) : 0; $record_end = ($record_start + $per_page) > $total_rows ? $total_rows : ($record_start + $per_page); if($total_pages > 1){ $first_display_page = $page - $default_options['paging_range']; $first_display_page = $first_display_page < 1 ? 1 : $first_display_page; $last_display_page = $page + $default_options['paging_range']; $last_display_page = $last_display_page > $total_pages ? $total_pages : $last_display_page; for($p = $first_display_page; $p <= $last_display_page; $p++){ 'page' => $p, 'text' => $p, 'link' => '' ); if($options['first_last_link'] === true && $first_display_page === $p && $first_display_page > 1){ $page_data['text'] = $default_options['first_character']; $page_data['page'] = 1; }elseif($options['first_last_link'] === true && $last_display_page === $p && $total_pages > $p){ $page_data['text'] = $default_options['last_character']; $page_data['page'] = $total_pages; } $page_list[] = $page_data; } } $pages .= '<ul class="list">'; foreach($page_list as $single_page){ $pages .= '<li class="'.($single_page['page'] == $page ? ' selected' : false ).'"><span><a href="'.$single_page['link'].'">'.$single_page['text'].'</a></span></li>'; } $pages .= '</ul>'; } return $pages; }