
今天准备修改一个帝国CMS的列表页的分页样式,突然发现一篇文章,写的非常好,就是关于如何自定义一个列表页分页样式的,看了看,基本上理论可以行得通而且简单操作,就做了一个简单的记录,希望能够帮助到自己,也能够帮助到需要的小伙伴们。
第一步:系统设置
进入帝国cms后台,点击系统设置—->系统参数设置—->信息设置,里面有个”列表分页函数(列表)”选项,将里面的函数名修改为user_ShowListMorePage

注意,是将内容分页函数处的函数名字改为user_ShowListMorePage

第二步:代码设置
复制t_function.php
列表式分页代码到e/class/userfun.php
中,记得这个文件如果没有做过修改,基本上属于空白,把复制过来的代码一定要转贴在 <?php ?>
之间,如果不知道是那段代码,大家可以看一下下面的代码:
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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
| //列表模板之列表式分页 function sys_ShowListMorePage($num,$page,$dolink,$type,$totalpage,$line,$ok,$search="",$add){ global $fun_r,$public_r //num是取得的当前总的文章数,line是栏目设定里的一页显示多少文章数。如果当前文章总数少于设定数,中断程序返回,并且什么也不显示。 if($num<=$line) { $pager['showpage']=''; return $pager; } //文件名 if(empty($add['dofile'])) { $add['dofile']='index'; } //静态页数 $repagenum=$add['repagenum']; //listpagelistnum是"系统参数设置" 里的 "信息设置" 下的 "列表分页函数(列表)"下的 "每页显示12个页码"这一项。 $page_line=$public_r['listpagelistnum']; //这个$snum可以控制 "当前页" 显示的位置,设置成2,当前页就显示在第3个位置。 $snum=2; //$totalpage=ceil($num/$line);//取得总页数 $firststr='<a title="Total record"> <b>'.$num.'</b> </a> ';//显示总文章数 //上一页 if($page<>1) { //若当前页不是第一页,则显示它的上一页链接 //$dolink是栏目的地址,$type是网页文件的扩展名,比如 .html ,那个$type之前有个点,是起连接作用的连接符,也就是说$type里面的内容是 .html $toppage='<a href="'.$dolink.$add['dofile'].$type.'">'.$fun_r['startpage'].'</a> '; $pagepr=$page-1; if($pagepr==1) { $prido=$add['dofile'].$type; } else { $prido=$add['dofile'].'_'.$pagepr.$type; } $prepage='<a href="'.$dolink.$prido.'">'.$fun_r['pripage'].'</a>'; } //下一页 if($page!=$totalpage) { //如果当前页不是最后一页,则显示它的下一页链接 $pagenex=$page+1; $nextpagelink=$repagenum&&$repagenum<$pagenex?eReturnRewritePageLink2($add,$pagenex):$dolink.$add['dofile'].'_'.$pagenex.$type; $lastpagelink=$repagenum&&$repagenum<$totalpage?eReturnRewritePageLink2($add,$totalpage):$dolink.$add['dofile'].'_'.$totalpage.$type; $nextpage=' <a href="'.$nextpagelink.'">'.$fun_r['nextpage'].'</a>'; $lastpage=' <a href="'.$lastpagelink.'">'.$fun_r['lastpage'].'</a>'; } //通过判断当前页码与上面讲述的snum的大小,确定页码显示的状态。如果$page-$snum<1,$starti赋值为1,否则$starti赋值为$page-$snum。 $starti=$page-$snum<1?1:$page-$snum; $no=0; //此处的for循环就是用来显示页码的,包括从第几个页码开始显示,以及当前页码加粗和显示多少个页码 for($i=$starti;$i<=$totalpage&&$no<$page_line;$i++) { $no++; //如果是当前页码,则加粗,有需要修改当前页码样式的可在此修改 if($page==$i) { $is_1="<b>"; $is_2="</b>"; } //如果当前页是首页 elseif($i==1) { $is_1='<a href="'.$dolink.$add['dofile'].$type.'">'; $is_2="</a>"; } //其余的页码,可以通过给a加样式来修改显示效果 else { $thispagelink=$repagenum&&$repagenum<$i?eReturnRewritePageLink2($add,$i):$dolink.$add['dofile'].'_'.$i.$type; $is_1='<a href="'.$thispagelink.'">'; $is_2="</a>"; } $returnstr.=' '.$is_1.$i.$is_2;//$returnstr即是生成的显示页号的代码 } $returnstr=$firststr.$toppage.$prepage.$returnstr.$nextpage.$lastpage; $pager['showpage']=$returnstr; return $pager; }
|
第三步:修改代码的函数名字
复制过来的函数名称为:
1
| function sys_ShowListMorePage($num,$page,$dolink,$type,$totalpage,$line,$ok,$search="",$add){
|
将其修改为
1
| function user_ShowListMorePage($num,$page,$dolink,$type,$totalpage,$line,$ok,$search=""){
|
最后的代码样式如下:
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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
| function user_ShowListMorePage($num,$page,$dolink,$type,$totalpage,$line,$ok,$search=""){ global $fun_r,$public_r; if($num<=$line) { $pager['showpage']=''; return $pager; } $page_line=$public_r['listpagelistnum']; $snum=2; //上一页 if($page<>1) { $toppage='<a href="'.$dolink.'index'.$type.'" class="disabled">'.$fun_r['startpage'].'</a>'; //首页 $pagepr=$page-1; if($pagepr==1) { $prido="index".$type; } else { $prido="index_".$pagepr.$type; } $prepage='<a href="'.$dolink.$prido.'" class="disabled">'.$fun_r['pripage'].'</a>'; //上一页 } //下一页 if($page!=$totalpage) { $pagenex=$page+1; $nextpage='<a href="'.$dolink.'index_'.$pagenex.$type.'" class="disabled">'.$fun_r['nextpage'].'</a>'; //下一页 $lastpage='<a href="'.$dolink.'index_'.$totalpage.$type.'" class="disabled">'.$fun_r['lastpage'].'</a>'; //最后一页 } $starti=$page-$snum<1?1:$page-$snum; $no=0; for($i=$starti;$i<=$totalpage&&$no<$page_line;$i++) //详细页码信息 { $no++; if($page==$i) { $is_1="<a class='cur'>"; //当前 $is_2="</a>"; } elseif($i==1) { $is_1='<a href="'.$dolink.'index'.$type.'">'; //第一页 $is_2="</a>"; } else { $is_1='<a href="'.$dolink.'index_'.$i.$type.'">'; //其他页 $is_2="</a>"; } $returnstr.=$is_1.$i.$is_2; } $returnstr=$firststr.$toppage.$prepage.$returnstr.$nextpage.$lastpage; $pager['showpage']=$returnstr; return $pager; }
|
第四步:代码调用
内容页或者需要代码分页的地方调用的地方,填写如下代码
最后在网页端显示的样式如截图

展现的代码如下:
1 2 3 4 5 6 7 8
| <div class="pageBox pTB20"> <a class="cur">1</a> <a href="/liaotian/index_2.html">2</a> <a href="/liaotian/index_3.html">3</a> <a href="/liaotian/index_4.html">4</a> <a href="#" class="disabled">下一页</a> <a href="#" class="disabled">尾页</a> </div>
|
第五步:需要添加的前端样式
当然了,我们还需要把如下的CSS样式添加到对应的样式文件中:
1 2 3 4 5 6 7 8
| /*** page -------------------------------------------------------------- ****/ .pageBox {text-align: center;} .pageBox a {border:1px solid #ddd;display:inline-block;margin-right:6px;color: #707070;width:34px;height:34px;font:bold 14px/34px arial;} .pageBox a:hover,.pageBox a:active{background:#3aa9f2;color: #FFFFFF;text-decoration: none;} .pageBox .cur { background: #3aa9f2;border: 1px solid #3aa9f2;text-decoration: none;} .pageBox a.cur {color: #fff;} .pageBox .disabled {width: 79px;}
|
好了,希望能够帮助到大家。