thinkphp 漂亮的分页 二次改进
我们thinkphp默认的分页,不太好写css
特别是显示边框的不太好美化
原始的代码如下:2774 条记录 1/139 页<br>
<a>下一页</a><br>
<span>1</span><br>
<a>2</a><br>
<a>3</a><br>
<a>4</a><br>
<a>5</a> <br>
<a>下5页</a> <br>
<a>最后一页</a>
我个人喜欢给a标签加边框,但是当前页,与总数都没有标签或不是a标题,css不太好写
一般结果如下图
当然,css比较厉害的,还是可以写出很漂亮的出来,对于css新手不太好写
下面我们将须要改变分页类 目录 ThinkPHP\Extend\Library\ORG\Util\Page.class.php
修改代码//修改当前页代码<br>
//原始代码<br>
//$linkPage .= "<span>".$page."</span>";<br>
//修改为<br>
$linkPage .= "<a>".$page."</a>";<br>
<br>
//修改分页记录总数<br>
//原始代码<br>
// protected $config = array('header'=>'条记录','prev'=>'上一页','next'=>'下一页','first'=>'第一页','last'=>'最后一页','theme'=>' %totalRow% %header% %nowPage%/%totalPage% 页 %upPage% %downPage% %first% %prePage% %linkPage% %nextPage% %end%');<br>
//theme改成以下<br>
'theme'=>'%upPage% %downPage% %first% %prePage% %linkPage% %nextPage% %end% <a>%totalRow% %header% %nowPage%/%totalPage% 页</a>'<br>
//默认的总数 如 2774 条记录 1/139 页 是排在前面的,我们把他移到后面去<br>
//就是把 %totalRow% %header% %nowPage%/%totalPage% 放到最后<br>
//分页类改完了
看不明白修改哪些,直接下载我修改好的 代码我放在最后面哈
下面css代码与div<style><br />
.p{overflow:hidden;margin:0;padding:0;}<br />
.p a{float:left;display:block;overflow:hidden;margin:5px;padding:3px 8px; border:1px solid #CCC;}<br />
.p a:hover{background-color:#333;color:#FFF;}<br />
.p a.current{background-color:#333;color:#FFF;}<br />
</style>
<br>
<div>$分页变量</div>
<br>
//感谢您的支持<br>
//本代码只代表个人观点,并不代表完美准解<br>
//更多PHP编码交流可加我QQ 839024615 微信: flash127
最终效果如下
分页类代码如下<?php <br />
// +----------------------------------------------------------------------<br>
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]<br>
// +----------------------------------------------------------------------<br>
// | Copyright (c) 2009 http://thinkphp.cn All rights reserved.<br>
// +----------------------------------------------------------------------<br>
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )<br>
// +----------------------------------------------------------------------<br>
// | Author: liu21st <liu21st><br>
// | lanfengye <zibin_5257><br>
// +----------------------------------------------------------------------<br>
<br>
class Page {<br>
<br>
// 分页栏每页显示的页数<br>
public $rollPage = 5;<br>
// 页数跳转时要带的参数<br>
public $parameter ;<br>
// 分页URL地址<br>
public $url = '';<br>
// 默认列表每页显示行数<br>
public $listRows = 20;<br>
// 起始行数<br>
public $firstRow ;<br>
// 分页总页面数<br>
protected $totalPages ;<br>
// 总行数<br>
protected $totalRows ;<br>
// 当前页数<br>
protected $nowPage ;<br>
// 分页的栏的总页数<br>
protected $coolPages ;<br>
// 分页显示定制<br>
protected $config = array('header'=>'条记录','prev'=>'上一页','next'=>'下一页','first'=>'第一页','last'=>'最后一页','theme'=>'%upPage% %downPage% %first% %prePage% %linkPage% %nextPage% %end% <a> %totalRow% %header% %nowPage%/%totalPage% 页</a>');<br>
// 默认分页变量名<br>
protected $varPage;<br>
<br>
/**<br>
* 架构函数<br>
* @access public<br>
* @param array $totalRows 总的记录数<br>
* @param array $listRows 每页显示记录数<br>
* @param array $parameter 分页跳转的参数<br>
*/<br>
public function __construct($totalRows,$listRows='',$parameter='',$url='') {<br>
$this->totalRows = $totalRows;<br>
$this->parameter = $parameter;<br>
$this->varPage = C('VAR_PAGE') ? C('VAR_PAGE') : 'p' ;<br>
if(!empty($listRows)) {<br>
$this->listRows = intval($listRows);<br>
}<br>
$this->totalPages = ceil($this->totalRows/$this->listRows); //总页数<br>
$this->coolPages = ceil($this->totalPages/$this->rollPage);<br>
$this->nowPage = !empty($_GET[$this->varPage])?intval($_GET[$this->varPage]):1;<br>
if($this->nowPage
$this->nowPage = 1;<br>
}elseif(!empty($this->totalPages) && $this->nowPage>$this->totalPages) {<br>
$this->nowPage = $this->totalPages;<br>
}<br>
$this->firstRow = $this->listRows*($this->nowPage-1);<br>
if(!empty($url)) $this->url = $url; <br>
}<br>
<br>
public function setConfig($name,$value) {<br>
if(isset($this->config[$name])) {<br>
$this->config[$name] = $value;<br>
}<br>
}<br>
<br>
/**<br>
* 分页显示输出<br>
* @access public<br>
*/<br>
public function show() {<br>
if(0 == $this->totalRows) return '';<br>
$p = $this->varPage;<br>
$nowCoolPage = ceil($this->nowPage/$this->rollPage);<br>
<br>
// 分析分页参数<br>
if($this->url){<br>
$depr = C('URL_PATHINFO_DEPR');<br>
$url = rtrim(U('/'.$this->url,'',false),$depr).$depr.'__PAGE__';<br>
}else{<br>
if($this->parameter && is_string($this->parameter)) {<br>
parse_str($this->parameter,$parameter);<br>
}elseif(is_array($this->parameter)){<br>
$parameter = $this->parameter;<br>
}elseif(empty($this->parameter)){<br>
unset($_GET[C('VAR_URL_PARAMS')]);<br>
$var = !empty($_POST)?$_POST:$_GET;<br>
if(empty($var)) {<br>
$parameter = array();<br>
}else{<br>
$parameter = $var;<br>
}<br>
}<br>
$parameter[$p] = '__PAGE__';<br>
$url = U('',$parameter);<br>
}<br>
//上下翻页字符串<br>
$upRow = $this->nowPage-1;<br>
$downRow = $this->nowPage+1;<br>
if ($upRow>0){<br>
$upPage = "<a>".$this->config['prev']."</a>";<br>
}else{<br>
$upPage = '';<br>
}<br>
<br>
if ($downRow totalPages){<br>
$downPage = "<a>".$this->config['next']."</a>";<br>
}else{<br>
$downPage = '';<br>
}<br>
// >><br>
if($nowCoolPage == 1){<br>
$theFirst = '';<br>
$prePage = '';<br>
}else{<br>
$preRow = $this->nowPage-$this->rollPage;<br>
$prePage = "<a>上".$this->rollPage."页</a>";<br>
$theFirst = "<a>".$this->config['first']."</a>";<br>
}<br>
if($nowCoolPage == $this->coolPages){<br>
$nextPage = '';<br>
$theEnd = '';<br>
}else{<br>
$nextRow = $this->nowPage+$this->rollPage;<br>
$theEndRow = $this->totalPages;<br>
$nextPage = "<a>下".$this->rollPage."页</a>";<br>
$theEnd = "<a>".$this->config['last']."</a>";<br>
}<br>
// 1 2 3 4 5<br>
$linkPage = "";<br>
for($i=1;$irollPage;$i++){<br>
$page = ($nowCoolPage-1)*$this->rollPage+$i;<br>
if($page!=$this->nowPage){<br>
if($pagetotalPages){<br>
$linkPage .= "<a>".$page."</a>";<br>
}else{<br>
break;<br>
}<br>
}else{<br>
if($this->totalPages != 1){<br>
$linkPage .= "<a>".$page."</a>";<br>
}<br>
}<br>
}<br>
$pageStr = str_replace(<br>
array('%header%','%nowPage%','%totalRow%','%totalPage%','%upPage%','%downPage%','%first%','%prePage%','%linkPage%','%nextPage%','%end%'),<br>
array($this->config['header'],$this->nowPage,$this->totalRows,$this->totalPages,$upPage,$downPage,$theFirst,$prePage,$linkPage,$nextPage,$theEnd),$this->config['theme']);<br>
return $pageStr;<br>
}<br>
<br>
}</zibin_5257></liu21st>
AD:真正免费,域名+虚机+企业邮箱=0元