thinkphp分页中间省略号实现<?phpclassPages{public$firstRow;//起始行数public$listRows;//列表每页显示行数public$parameter;//分页跳转时要带的参数public$totalRows;//总行数public$totalPages;//分页总页面数public$rollPage=5;//分页栏每页显示的页数public$lastSuffix=true;//最后一页是否显示总页数private$p='p';//分页参数名private$url='';//当前链接URLprivate$nowPage=1;//分页显示定制private$config=array('header'=>'<inputtype="hidden"id="totalPage"value="%totalPage%"><span>Gotopage:</span><inputtype="text"value="1"id="fanyePage"/><inputtype="button"name=""id="pagebutton"value="GO"/>','first'=>'首页','prev'=>'PrevPage','next'=>'NextPage','last'=>'末页','theme'=>'%FIRST%%UP_PAGE%%LINK_PAGE%%DOWN_PAGE%%END%%HEADER%',);/***架构函数*@paramarray$totalRows总的记录数*@paramarray$listRows每页显示记录数*@paramarray$parameter分页跳转的参数*/publicfunction__construct($totalRows,$listRows=20,$parameter=array()){C('VAR_PAGE')&&$this->p=C('VAR_PAGE');//设置分页参数名称/*基础设置*/$this->totalRows=$totalRows;//设置总记录数$this->listRows=$listRows;//设置每页显示行数$this->totalPages=ceil($this->totalRows/$this->listRows);//总页数$this->parameter=empty($parameter)?$_GET:$parameter;$this->nowPage=empty($_GET[$this->p])?1:intval($_GET[$this->p]);$this->nowPage=$this->nowPage>0?$this->nowPage:1;$this->firstRow=$this->listRows*($this->nowPage-1);if($this->nowPage<1){$this->nowPage=1;}elseif(!empty($this->totalPages)&&$this->nowPage>$this->totalPages){$this->nowPage=$this->totalPages;}}/***定制分页链接设置*@paramstring$name设置名称*@paramstring$value设置值*/publicfunctionsetConfig($name,$value){if(isset($this->config[$name])){$this->config[$name]=$value;}}/***生成链接URL*@paraminteger$page页码*@returnstring*/privatefunctionurl($page){//dump(urlencode('[PAGE]'));//returnstr_replace(urlencode('[PAGE]'),$page,$this->url);$url=str_replace(urlencode('[PAGE]'),$page,$this->url);$url=str_replace(".html","",'http://'.$_SERVER['SERVER_NAME'].':'.$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"].'/p/'.$page);if($_GET['p']){$url=str_replace("/p/".$_GET['p']."","",'http://'.$_SERVER['SERVER_NAME'].':'.$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"].'/p/'.$page);}$url=str_replace(".html","",$url).'.html';return$url;}/***组装分页链接*@returnstring*/publicfunctionshow(){$adjacents=2;if(0==$this->totalRows)return'';$this->parameter[$this->p]='[PAGE]';$this->url=U(ACTION_NAME,$this->parameter);/*计算分页信息*/$this->totalPages=ceil($this->totalRows/$this->listRows);//总页数if(!empty($this->totalPages)&&$this->nowPage>$this->totalPages){$this->nowPage=$this->totalPages;}//上下翻页字符串$upRow=$this->nowPage-1;$downRow=$this->nowPage+1;//上一页if($upRow>0){$pages.="<ahref='".$this->url($upRow)."'class='prev'>".$this->config['prev']."</a>";}else{$pages.="<aclass='prevcurrent'>".$this->config['prev']."</a>";}//第一页if($this->nowPage>($adjacents+1)){$pages.="<ahref='".$this->url(1)."'>1</a>";}//添加省略号if($this->nowPage>($adjacents+2)){$pages.="<a>...</a>";}//12345$pmin=($this->nowPage>$adjacents)?($this->nowPage-$adjacents):1;$pmax=($this->nowPage<($this->totalPages-$adjacents))?($this->nowPage+$adjacents):$this->totalPages;for($i=$pmin;$i<=$pmax;$i++){if($i==$this->nowPage){$pages.="<aclass='on'>".$i."</a>";}else{$pages.="<ahref='".$this->url($i)."'>".$i."</a>";}}//添加省略号if($this->nowPage<($this->totalPages-$adjacents-1)){$pages.="<a>...</a>";}//最后一页if($this->nowPage<($this->totalPages-$adjacents)){$pages.="<ahref='".$this->url($this->totalPages)."'>".$this->totalPages."</a>";}//下一页if($downRow<=$this->totalPages){$pages.="<ahref='".$this->url($downRow)."'class='next'>".$this->config['next']."</a>";}else{$pages.="<aclass='nextcurrent'>".$this->config['next']."</a>";}$pages.='<inputtype="hidden"id="totalPage"value="%totalPage%"><span>Gotopage:</span><inputtype="text"value="1"id="fanyePage"/><inputtype="button"name=""id="pagebutton"value="GO"/>';return$pages;}}<divclass="yPub_fan">{$page}</div>分页跳转方式<script>$('#pagebutton').click(function(){<?php$SELF=$_SERVER['REQUEST_URI'];$SELF=str_replace(".html","",$SELF);?>vartotalPage=parseInt($('#totalPage').val());varfanyePage=parseInt($('#fanyePage').val());if(!fanyePage){returnfalse;}if(totalPage<fanyePage){layer.alert('不能大于总页数');returnfalse;}window.location.href="<?phpecho$SELF?>/p/"+fanyePage;});</script>