diff --git a/system/includes/functions.php b/system/includes/functions.php index 7b5879a..600bfa3 100644 --- a/system/includes/functions.php +++ b/system/includes/functions.php @@ -1346,15 +1346,120 @@ function has_pagination($total, $perpage, $page = 1) if (!$total) { $total = count(get_post_unsorted()); } - $totalPage = ceil($total / $perpage); - $number = 'Page '. $page . ' of ' . $totalPage; + $totalPage = ceil($total / $perpage); + $number = 'Page '. $page . ' of ' . $totalPage; + $pager = get_pagination($page, $total, $perpage, 2); return array( 'prev' => $page > 1, 'next' => $total > $page * $perpage, - 'number' => $number + 'pagenum' => $number, + 'html' => $pager, + 'items' => $total, + 'perpage' => $perpage ); } +//function to return the pagination string +function get_pagination($page = 1, $totalitems, $perpage = 10, $adjacents = 1, $pagestring = '?page=') +{ + //defaults + if(!$adjacents) $adjacents = 1; + if(!$perpage) $perpage = 10; + if(!$page) $page = 1; + + //other vars + $prev = $page - 1; //previous page is page - 1 + $next = $page + 1; //next page is page + 1 + $lastpage = ceil($totalitems / $perpage); //lastpage is = total items / items per page, rounded up. + $lpm1 = $lastpage - 1; //last page minus 1 + + /* + Now we apply our rules and draw the pagination object. + We're actually saving the code to a variable in case we want to draw it more than once. + */ + $pagination = ''; + if($lastpage > 1) + { + $pagination .= '