-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpaginate.php
executable file
·48 lines (46 loc) · 1.9 KB
/
paginate.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
/*--------------------------------------------------------------------------------------------
| @desc: pagination
| @author: Aravind Buddha
| @url: http://www.techumber.com
| @date: 12 August 2012
| @email aravind@techumber.com
| @license: Free!, to Share,copy, distribute and transmit ,
| but i'll be glad if i my name listed in the credits'
---------------------------------------------------------------------------------------------*/
function paginate($reload, $page, $tpages) {
$adjacents = 2;
$prevlabel = "‹ Prev";
$nextlabel = "Next ›";
$out = "<ul>";
// previous
if ($page == 1) {
$out.= "<span>" . $prevlabel . "</span>\n";
} elseif ($page == 2) {
$out.= "<li><a href=\"" . $reload . "\">" . $prevlabel . "</a>\n</li>";
} else {
$out.= "<li><a href=\"" . $reload . "&page=" . ($page - 1) . "\">" . $prevlabel . "</a>\n</li>";
}
$pmin = ($page > $adjacents) ? ($page - $adjacents) : 1;
$pmax = ($page < ($tpages - $adjacents)) ? ($page + $adjacents) : $tpages;
for ($i = $pmin; $i <= $pmax; $i++) {
if ($i == $page) {
$out.= "<li class=\"active_page\"><a href=''>" . $i . "</a></li>\n";
} elseif ($i == 1) {
$out.= "<li><a href=\"" . $reload . "\">" . $i . "</a>\n</li>";
} else {
$out.= "<li><a href=\"" . $reload . "&page=" . $i . "\">" . $i . "</a>\n</li>";
}
}
if ($page < ($tpages - $adjacents)) {
$out.= "<a href=\"" . $reload . "&page=" . $tpages . "\">" . $tpages . "</a>\n";
}
// next
if ($page < $tpages) {
$out.= "<li><a href=\"" . $reload . "&page=" . ($page + 1) . "\">" . $nextlabel . "</a>\n</li>";
} else {
$out.= "<span>" . $nextlabel . "</span>\n";
}
$out.= "</ul>";
return $out;
}