phpcms自定义分页

在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) {.......}

 /**
* 测试分页函数
*
* @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默认就行了

 $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&amp;ToPage=1">首页</a>|
// <a href="?classid=1&amp;ToPage=1">上一页</a>|
// <a href="?classid=1&amp;ToPage=3">下一页</a>|
// <a href="?classid=1&amp;ToPage=5"> 最后页</a>|
}
return $multipage;
}

首页时

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAATAAAAAgCAIAAAAaOLOLAAAABmJLR0QAAAAAAAD5Q7t/AAAACXBIWXMAAA7EAAAOxAGVKw4bAAADiklEQVR4nO2ZzW3jMBCF1ZG7yHE70D1NbAHqYJEqhGwbewngfriyHdHU/JNUslzgfRACekRzHmf4IseZ/gAAhmFKAIBhgCEBGAgYEoCBgCEBGAgYEoCBgCEBGAgYEoCBgCEBGAgYEoCBCBlyevnhRkhQnFDLtoh9eQv0QlLYGYN6gtNcjHXsfv3zqp5CxS4+3pZ3faE7DXUg087SEzJkipktMqeHr1jThhTUbZhRGb9PAbQK83XivajV0IlRioaCZKw3xgwZicR1NuvxDRmvXfwQKFzTZUrT45rJvaYFCWtars9X855rlSM547S7sXyZx/aVCrrrc4PLaNaTOmSYHOusc1Z2Z52YIU+sVY+ekCHdePwEmFzTsqYjJ628my0flHXex+un+XnEO995bS4mWJyWjew0vzGdWFUOqbNJZ7roLmKGbIjwCf16zjEkj4jv8louG1Kc6lZH4Gm5lJbL88G4zFtmIWJmsTfbFnGJtNyIi+MSEvf6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f4a+zQdLvhSW0qPdabZe2u3PusiZRYVa5cuQ1MpXq7rPqvY6VgcztT0DEV4knozfe/KIp2aUu5+YgPR+sHx+hI9dk+yIpcxyNy4Z1SlHFsmhZM+YtCDtsE/EkwU5I7xMPL3etxTYDeXYyJM0BnOw2/mcuv94T99/1taMowaQAzMirE2pxsEsWJvyoDmWDLbMQ/O0dEQoj69PmQYx79ssAQBCQDwABIF4AAgC8QAQBOIBIAjEA0AQiAeAIBAPAEEgHgCC/AEmuXOF4G8ifwAAAABJRU5ErkJggg==" alt="" />

写完这个之后再
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);';

上一篇:一起来学Spring Cloud | 第一章 :如何搭建一个多模块的springcloud项目


下一篇:MySQL用户管理、常用sql语句、MySQL数据库备份恢复