Zebra_Pagination 2.0 不再支持 PHP 4 ,要求至少 PHP 5 版本,修复了 URL 中包含 HTML 内容的 bug,上一页和下一页显示关联的标签等。
Zebra_Pagination 是一个通用的 PHP 类,用来根据记录数和每页显示数自动生成分页链接。
示例代码:
01 | <?php |
02 | // let's paginate data from an array... |
03 | $countries = array ( |
04 | // array of countries |
05 | ); |
06 |
07 | // how many records should be displayed on a page? |
08 | $records_per_page = 10; |
09 |
10 | // include the pagination class |
11 | require 'path/to/Zebra_Pagination.php' ; |
12 |
13 | // instantiate the pagination object |
14 | $pagination = new Zebra_Pagination(); |
15 |
16 | // the number of total records is the number of records in the array |
17 | $pagination ->records( count ( $countries )); |
18 |
19 | // records per page |
20 | $pagination ->records_per_page( $records_per_page ); |
21 |
22 | // here's the magick: we need to display *only* the records for the current page |
23 | $countries = array_slice ( |
24 | $countries , |
25 | (( $pagination ->get_page() - 1) * $records_per_page ), |
26 | $records_per_page |
27 | ); |
28 |
29 | ?> |
30 |
31 | <table> |
32 |
33 | <tr><th>Country</th></tr> |
34 |
35 | <?php foreach ( $countries as $index => $country ):?> |
36 |
37 | <tr<?php echo $index % 2 ? ' class="even"' : '' )?>> |
38 | <td><?php echo $country ?></td> |
39 | </tr> |
40 |
41 | <?php endforeach ?> |
42 |
43 | </table> |
44 |
45 | <?php |
46 |
47 | // render the pagination links |
48 | $pagination ->render(); |
49 |
50 | ?> |