在global.func.php中找到分页函数
function pages($num, $curr_page, $perpage = 20, $urlrule = ‘', $array = array(),$setpages = 10) {…….}
复制一下改个名例如叫
function test_pages($num, $curr_page, $perpage = 20, $urlrule = ‘', $array = array(),$setpages = 10) {…….}
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
|
/**
* 测试分页函数
*
* @param $num 信息总数
* @param $curr_page 当前分页
* @param $perpage 每页显示数
* @param $urlrule URL规则
* @param $array 需要传递的数组,用于增加额外的方法
* @return 分页
*/
function test_pages($num, $curr_page, $perpage = 20, $urlrule = '', $array = array(),$setpages = 10) {
if(defined('URLRULE') && $urlrule == '') {
$urlrule = URLRULE;
$array = $GLOBALS['URL_ARRAY'];
} elseif($urlrule == '') {
$urlrule = url_par('page={$page}');
}
$multipage = '';
if($num > $perpage) {
$page = $setpages+1;
$offset = ceil($setpages/2-1);
$pages = ceil($num / $perpage);
if (defined('IN_ADMIN') && !defined('PAGES')) define('PAGES', $pages);
$from = $curr_page - $offset;
$to = $curr_page + $offset;
$more = 0;
if($page >= $pages) {
$from = 2;
$to = $pages-1;
} else {
if($from <= 1) {
$to = $page-1;
$from = 2;
} elseif($to >= $pages) {
$from = $pages-($page-2);
$to = $pages-1;
}
$more = 1;
}
|
从这里网上是分页的核心部分,不能改变往下就是一些分页样式了,自己按照形式来把,这是我写的比较简单的分页样式后面有图
并且这里我比较懒的没有用语言包,有兴趣的朋友可以把所有的中文放到语言包中
变量解释 $pages == 总页数 $curr_page == 当前页 pageurl($urlrule, 第n页, $array)函数用于生成url ,$urlrule和$array默认就行了
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
|
$multipage .= '总共:<font color="#ff0000">'. $pages.'</font>页, <font color="#ff0000">'. $num .'</font>篇文章, ';
$multipage .= '当前页:<font color="#ff0000"> '. $curr_page .' </font>';
if($curr_page>0){
if($curr_page==1){
$multipage .= '<a href="'. pageurl($urlrule, $curr_page+1, $array) .'">下一页</a>|';
$multipage .= '<a href="'. pageurl($urlrule, $pages, $array) .'"> 最后页</a>|';
}
else if($curr_page < $pages){
$multipage .= '<a href="'. pageurl($urlrule, 1, $array) .'">首页</a>|';
$multipage .= '<a href="'. pageurl($urlrule, $curr_page-1, $array) .'">上一页</a>|';
$multipage .= '<a href="'. pageurl($urlrule, $curr_page+1, $array) .'">下一页</a>|';
$multipage .= '<a href="'. pageurl($urlrule, $pages, $array) .'"> 最后页</a>|';
}
else if($curr_page == $pages){
$multipage .= '<a href="'. pageurl($urlrule, 1, $array) .'">首页</a>|';
$multipage .= '<a href="'. pageurl($urlrule, $curr_page-1, $array) .'">上一页</a>|';
}
}
// 总共:<font color="#ff0000">5</font>页, <font color="#ff0000">199</font>篇文章,
// 当前页:<font color="#ff0000"> 2 </font>
// <a href="?classid=1&ToPage=1">首页</a>|
// <a href="?classid=1&ToPage=1">上一页</a>|
// <a href="?classid=1&ToPage=3">下一页</a>|
// <a href="?classid=1&ToPage=5"> 最后页</a>|
}
return $multipage;
}
|
首页时

中间页

最后一页

写完这个之后再
lib/classes/template_cache.class.php中找到
|
$str .= '$pages = pages($'.$op.'_total, $page, $pagesize, $urlrule);';
|
下面加一行
|
$str .= '$test_pages = test_pages($'.$op.'_total, $page, $pagesize, $urlrule);';
|
然后前台调用时候原来写的是{$pages} 现在写{$test_pages}就可以了
网上的教程中有一部分我没用到也好用了这里注释一下,以备
当然如果使用过程中,发现SQL分页的不能正常使用,再在\
|
$str .= ‘$r =$get_db->sql_query(“‘.$sql.’”);$s =$get_db->fetch_next();$pages=pages($s[\'count\'],$page, $pagesize, $urlrule);’;
|
添加这段代码:
|
$str .= '$r =$get_db->sql_query("'.$sql.'");$s =$get_db->fetch_next();$pages_my=pages_my($s[\'count\'],$page, $pagesize, $urlrule);';
|