分类分类
关注+2011-01-13作者:清晨
dedecms分页显示代码并设置样式教程
dedecms分页代码默认是<li>分页数据</li>,这样为我们设置样式带来了一定的难度。在这里做了将 li 标签修改 a 标签,方便设置样式。需要修改的有两个文件
一、include/arc.archives.class.php 修改代码如下(注释部分为原有代码,紧跟后面的是修改后的代码)
- //获得静态页面分页列表
- function GetPagebreak($totalPage,$nowPage,$aid)
- {
- if($totalPage==1)
- {
- return "";
- }
- //$PageList = "<li><a>共".$totalPage."页: </a></li>";
- $PageList = "<a>共".$totalPage."页: </a>";
- $nPage = $nowPage-1;
- $lPage = $nowPage+1;
- if($nowPage==1)
- {
- //$PageList.="<li><a href='#'>上一页</a></li>";
- $PageList.="<a href='#'>上一页</a>";
- }
- else
- {
- if($nPage==1)
- {
- //$PageList.="<li><a href='".$this->NameFirst.".".$this->ShortName."'>上一页</a></li>";
- $PageList.="<a href='".$this->NameFirst.".".$this->ShortName."'>上一页</a>";
- }
- else
- {
- //$PageList.="<li><a href='".$this->NameFirst."_".$nPage.".".$this->ShortName."'>上一页</a></li>";
- $PageList.="<a href='".$this->NameFirst."_".$nPage.".".$this->ShortName."'>上一页</a>";
- }
- }
- for($i=1;$i<=$totalPage;$i++)
- {
- if($i==1)
- {
- if($nowPage!=1)
- {
- //$PageList.="<li><a href='".$this->NameFirst.".".$this->ShortName."'>1</a></li>";
- $PageList.="<a href='".$this->NameFirst.".".$this->ShortName."'>1</a>";
- }
- else
- {
- //$PageList.="<li class=\"thisclass\"><a href='#'>1</a></li>";
- $PageList.="<a href='#' class='thisclass'>1</a>";
- }
- }
- else
- {
- $n = $i;
- if($nowPage!=$i)
- {
- //$PageList.="<li><a href='".$this->NameFirst."_".$i.".".$this->ShortName."'>".$n."</a></li>";
- $PageList.="<a href='".$this->NameFirst."_".$i.".".$this->ShortName."'>".$n."</a>";
- }
- else
- {
- //$PageList.="<li class=\"thisclass\"><a href='#'>{$n}</a></li>";
- $PageList.="<a href='#' class='thisclass'>{$n}</a>";
- }
- }
- }
- if($lPage <= $totalPage)
- {
- //$PageList.="<li><a href='".$this->NameFirst."_".$lPage.".".$this->ShortName."'>下一页</a></li>";
- $PageList.="<a href='".$this->NameFirst."_".$lPage.".".$this->ShortName."'>下一页</a>";
- }
- else
- {
- //$PageList.= "<li><a href='#'>下一页</a></li>";
- $PageList.= "<a href='#'>下一页</a>";
- }
- return $PageList;
- }
二、include/arc.listview.class.php 修改代码如下(注释部分为原有代码,紧跟后面的是修改后的代码)
- //获取静态的分页列表
- function GetPageListST($list_len,$listitem="index,end,pre,next,pageno")
- {
- $prepage = $nextpage = '';
- $prepagenum = $this->PageNo-1;
- $nextpagenum = $this->PageNo+1;
- if($list_len=='' || ereg("[^0-9]",$list_len))
- {
- $list_len=3;
- }
- $totalpage = ceil($this->TotalResult/$this->PageSize);
- if($totalpage<=1 && $this->TotalResult>0)
- {
- //return "<li><span class=\"pageinfo\">共 <strong>1</strong>页<strong>".$this->TotalResult."</strong>条记录</span></li>\r\n";
- return "<a class='current'>共 1 页 ".$this->TotalResult." 条记录</a>";
- }
- if($this->TotalResult == 0)
- {
- //return "<li><span class=\"pageinfo\">共 <strong>0</strong>页<strong>".$this->TotalResult."</strong>条记录</span></li>\r\n";
- return "<a class='current'>共 0 页 ".$this->TotalResult." 条记录</a>";
- }
- $purl = $this->GetCurUrl();
- //$maininfo = "<li><span class=\"pageinfo\">共 <strong>{$totalpage}</strong>页<strong>".$this->TotalResult."</strong>条</span></li>\r\n";
- $maininfo = "<a class='current'>共 {$totalpage} 页 ".$this->TotalResult." 条</a>";
- $tnamerule = $this->GetMakeFileRule($this->Fields['id'],"list",$this->Fields['typedir'],$this->Fields['defaultname'],$this->Fields['namerule2']);
- $tnamerule = ereg_replace('^(.*)/','',$tnamerule);
- //获得上一页和主页的链接
- if($this->PageNo != 1)
- {
- //$prepage.="<li><a href='".str_replace("{page}",$prepagenum,$tnamerule)."'>上一页</a></li>\r\n";
- $prepage.="<a href='".str_replace("{page}",$prepagenum,$tnamerule)."'>上一页</a>";
- //$indexpage="<li><a href='".str_replace("{page}",1,$tnamerule)."'>首页</a></li>\r\n";
- $indexpage="<a href='".str_replace("{page}",1,$tnamerule)."'>首页</a>";
- }
- else
- {
- //$indexpage="<li>首页</li>\r\n";
- $indexpage="<a class='current'>首页</a>";
- }
- //下一页,未页的链接
- if($this->PageNo!=$totalpage && $totalpage>1)
- {
- //$nextpage.="<li><a href='".str_replace("{page}",$nextpagenum,$tnamerule)."'>下一页</a></li>\r\n";
- $nextpage.="<a href='".str_replace("{page}",$nextpagenum,$tnamerule)."'>下一页</a>";
- //$endpage="<li><a href='".str_replace("{page}",$totalpage,$tnamerule)."'>末页</a></li>\r\n";
- $endpage="<a href='".str_replace("{page}",$totalpage,$tnamerule)."'>末页</a>";
- }
- else
- {
- //$endpage="<li>末页</li>\r\n";
- $endpage="<a class='current'>末页</a>";
- }
- //option链接
- $optionlist = '';
- $optionlen = strlen($totalpage);
- $optionlen = $optionlen*12 + 18;
- if($optionlen < 36) $optionlen = 36;
- if($optionlen > 100) $optionlen = 100;
- //$optionlist = "<li><select name='sldd' style='width:{$optionlen}px' onchange='location.href=this.options[this.selectedIndex].value;'>\r\n";
- $optionlist = "<select name='sldd' style='width:{$optionlen}px' onchange='location.href=this.options[this.selectedIndex].value;'>";
- for($mjj=1;$mjj<=$totalpage;$mjj++)
- {
- if($mjj==$this->PageNo)
- {
- $optionlist .= "<option value='".str_replace("{page}",$mjj,$tnamerule)."' selected>$mjj</option>\r\n";
- }
- else
- {
- $optionlist .= "<option value='".str_replace("{page}",$mjj,$tnamerule)."'>$mjj</option>\r\n";
- }
- }
- //$optionlist .= "</select></li>\r\n";
- $optionlist .= "</select>";
- //获得数字链接
- $listdd="";
- $total_list = $list_len * 2 + 1;
- if($this->PageNo >= $total_list)
- {
- $j = $this->PageNo-$list_len;
- $total_list = $this->PageNo+$list_len;
- if($total_list>$totalpage)
- {
- $total_list=$totalpage;
- }
- }
- else
- {
- $j=1;
- if($total_list>$totalpage)
- {
- $total_list=$totalpage;
- }
- }
- for($j;$j<=$total_list;$j++)
- {
- if($j==$this->PageNo)
- {
- //$listdd.= "<li class=\"current\">$j</li>\r\n";
- $listdd.= "<a class=\"current\">$j</a>";
- }
- else
- {
- //$listdd.="<li><a href='".str_replace("{page}",$j,$tnamerule)."'>".$j."</a></li>\r\n";
- $listdd.="<a href='".str_replace("{page}",$j,$tnamerule)."'>".$j."</a>";
- }
- }
- $plist = '';
- if(eregi('info',$listitem)) $plist .= $maininfo;
- if(eregi('index',$listitem)) $plist .= $indexpage;
- if(eregi('pre',$listitem)) $plist .= $prepage;
- if(eregi('pageno',$listitem)) $plist .= $listdd;
- if(eregi('next',$listitem)) $plist .= $nextpage;
- if(eregi('end',$listitem)) $plist .= $endpage;
- if(eregi('option',$listitem)) $plist .= $optionlist;
- return $plist;
- }
以上代码适用于 dedecms5.6
分页代码调用及样式如下
- <dd class="g_page">
- {dede:pagelist listsize='2' listitem='info,index,end,pre,next,pageno'/}
- </dd>
- .g_page{ width:100%; overflow:hidden; height:22px; text-align:center; margin-top:10px;}
- .g_page a{ display:inline-block; _display:inline; zoom:1; border:1px solid #ccc; height:20px; line-height:20px; padding:0 5px; text-decoration:underline; margin:0 5px 0 0;}
- .g_page .current{ text-decoration:none;}
相关文章
更多+相同厂商
热门推荐
点击查看更多
点击查看更多
点击查看更多
说两句网友评论