dedecms独立模型分页功能的完善(2)

独立模型:

/** * 获取动态的分页列表 * * @access public * @param int $list_len 列表宽度 * @param string $listitem 列表样式 * @return string */ function GetPageListDM($list_len,$listitem="index,end,pre,next,pageno") { global $nativeplace,$infotype,$keyword; if(empty($nativeplace)) $nativeplace = 0; if(empty($infotype)) $infotype = 0; if(empty($keyword)) $keyword = ''; $prepage = $nextpage = ''; $prepagenum = $this->PageNo - 1; $nextpagenum = $this->PageNo + 1; if($list_len=="" || preg_match("/[^0-9]/", $list_len)) { $list_len=3; } $totalpage = ceil($this->TotalResult / $this->PageSize); if($totalpage<=1 && $this->TotalResult>0) { return "<span class=\"pageinfo\">共1页/".$this->TotalResult."条记录</span>"; } if($this->TotalResult == 0) { return "<span class=\"pageinfo\">共0页/".$this->TotalResult."条记录</span>"; } $purl = $this->GetCurUrl(); $geturl = "tid=".$this->TypeID."&TotalResult=".$this->TotalResult."&nativeplace=$nativeplace&infotype=$infotype&keyword=".urlencode($keyword)."&"; $hidenform = "<input type='hidden' name='tid' value='".$this->TypeID."' />\r\n"; $hidenform = "<input type='hidden' name='nativeplace' value='$nativeplace' />\r\n"; $hidenform = "<input type='hidden' name='infotype' value='$infotype' />\r\n"; $hidenform = "<input type='hidden' name='keyword' value='$keyword' />\r\n"; $hidenform .= "<input type='hidden' name='TotalResult' value='".$this->TotalResult."' />\r\n"; $purl .= "?".$geturl; //获得上一页和下一页的链接 if($this->PageNo != 1) { $prepage.="<li><a href='".$purl."PageNo=$prepagenum'>上一页</a></li>\r\n"; $indexpage="<li><a href='".$purl."PageNo=1'>首页</a></li>\r\n"; } else { $indexpage="<li><a>首页</a></li>\r\n"; } if($this->PageNo!=$totalpage && $totalpage>1) { $nextpage.="<li><a href='".$purl."PageNo=$nextpagenum'>下一页</a></li>\r\n"; $endpage="<li><a href='".$purl."PageNo=$totalpage'>末页</a></li>\r\n"; } else { $endpage="<li><a>末页</a></li>"; } //获得数字链接 $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=\"thisclass\"><a>$j</a></li>\r\n"; } else { $listdd.="<li><a href='".$purl."PageNo=$j'>".$j."</a></li>\r\n"; } } $plist = $indexpage.$prepage.$listdd.$nextpage.$endpage; return $plist; }  

仔细观察 普通模型中在28行左右的位置多了句$maininfo = "<li><span class=\"pageinfo\">共 <strong>{$totalpage}</strong>页<strong>".$this->TotalResult."</strong>条</span></li>\r\n";而在独立模型中则没有。

而且在最后,普通模型中将$maininfo的值加入了$plist字符串中。(更细节的地方是普通模型还判断了标签中是否有info属性来决定是否加入:

if(preg_match('/info/i', $listitem)) $plist .= $maininfo;  

)独立模型中这些都省了。

要将独立模型修改过来很简单,不过“普通模型还判断了标签中是否有info属性来决定是否加入”这点我就不去实现了,这里不判断直接再任何情况下都加入maininfo:

/** * 获取动态的分页列表 * * @access public * @param int $list_len 列表宽度 * @param string $listitem 列表样式 * @return string */ function GetPageListDM($list_len,$listitem="index,end,pre,next,pageno") { global $nativeplace,$infotype,$keyword; if(empty($nativeplace)) $nativeplace = 0; if(empty($infotype)) $infotype = 0; if(empty($keyword)) $keyword = ''; $prepage = $nextpage = ''; $prepagenum = $this->PageNo - 1; $nextpagenum = $this->PageNo + 1; if($list_len=="" || preg_match("/[^0-9]/", $list_len)) { $list_len=3; } $totalpage = ceil($this->TotalResult / $this->PageSize); if($totalpage<=1 && $this->TotalResult>0) { return "<span class=\"pageinfo\">共1页/".$this->TotalResult."条记录</span>"; } if($this->TotalResult == 0) { return "<span class=\"pageinfo\">共0页/".$this->TotalResult."条记录</span>"; } $maininfo = "<li><span class=\"pageinfo\">共 <strong>{$totalpage}</strong>页<strong>".$this->TotalResult."</strong>条</span></li>\r\n"; $purl = $this->GetCurUrl(); $geturl = "tid=".$this->TypeID."&TotalResult=".$this->TotalResult."&nativeplace=$nativeplace&infotype=$infotype&keyword=".urlencode($keyword)."&"; $hidenform = "<input type='hidden' name='tid' value='".$this->TypeID."' />\r\n"; $hidenform = "<input type='hidden' name='nativeplace' value='$nativeplace' />\r\n"; $hidenform = "<input type='hidden' name='infotype' value='$infotype' />\r\n"; $hidenform = "<input type='hidden' name='keyword' value='$keyword' />\r\n"; $hidenform .= "<input type='hidden' name='TotalResult' value='".$this->TotalResult."' />\r\n"; $purl .= "?".$geturl; //获得上一页和下一页的链接 if($this->PageNo != 1) { $prepage.="<li><a href='".$purl."PageNo=$prepagenum'>上一页</a></li>\r\n"; $indexpage="<li><a href='".$purl."PageNo=1'>首页</a></li>\r\n"; } else { $indexpage="<li><a>首页</a></li>\r\n"; } if($this->PageNo!=$totalpage && $totalpage>1) { $nextpage.="<li><a href='".$purl."PageNo=$nextpagenum'>下一页</a></li>\r\n"; $endpage="<li><a href='".$purl."PageNo=$totalpage'>末页</a></li>\r\n"; } else { $endpage="<li><a>末页</a></li>"; } //获得数字链接 $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=\"thisclass\"><a>$j</a></li>\r\n"; } else { $listdd.="<li><a href='".$purl."PageNo=$j'>".$j."</a></li>\r\n"; } } $plist = $indexpage.$prepage.$listdd.$nextpage.$endpage;; return $plist; }  

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/200058616b289b722ced4b6f45d14c0a.html