dedecms其實(shí)在架構(gòu)方面沒什么問(wèn)題,但是估計(jì)里面有些功能是新手做的吧,有很多待完善的地方,比如分頁(yè)功能,從代碼可以直接看出當(dāng)時(shí)的負(fù)責(zé)人有敷衍了事的心里。
dede的分頁(yè)如果有兩個(gè)頁(yè)碼顯示的話,無(wú)法顯示出總的文章數(shù),舉個(gè)例子:
在普通文章模型下面,列表的分頁(yè)是這樣的:
但是在獨(dú)立模型中就成了這樣了
最后面的共*頁(yè)*條的信息不見了,相信遇到這個(gè)問(wèn)題的同學(xué)首先想到的是自己哪里用錯(cuò)了,其實(shí)不是,dede獨(dú)立模型這里的代碼是偷工減料了的。處理獨(dú)立模型列表的代碼在arc.sglistview.class.php中,我們比較下同樣負(fù)責(zé)顯示分頁(yè)的代碼段,獨(dú)立模型和普通模型中有什么區(qū)別:
普通文章模型:
/** * 獲取動(dòng)態(tài)的分頁(yè)列表 * * @access public * @param string $list_len 列表寬度 * @param string $list_len 列表樣式 * @return string */ function GetPageListDM($list_len,$listitem="index,end,pre,next,pageno") { global $cfg_rewrite; $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 "<li><span class=\"pageinfo\">共 1 頁(yè)/".$this->TotalResult." 條記錄</span></li>\r\n"; } if($this->TotalResult == 0) { return "<li><span class=\"pageinfo\">共 0 頁(yè)/".$this->TotalResult." 條記錄</span></li>\r\n"; } $maininfo = "<li><span class=\"pageinfo\">共 <strong>{$totalpage}</strong>頁(yè)<strong>".$this->TotalResult."</strong>條</span></li>\r\n"; $purl = $this->GetCurUrl(); // 如果開啟為靜態(tài),則對(duì)規(guī)則進(jìn)行替換 if($cfg_rewrite == 'Y') { $nowurls = preg_replace("/\-/", ".php?", $purl); $nowurls = explode("?", $nowurls); $purl = $nowurls[0]; } $geturl = "tid=".$this->TypeID."&TotalResult=".$this->TotalResult."&"; $purl .= '?'.$geturl; $optionlist = ''; //$hidenform = "<input type='hidden' name='tid' value='".$this->TypeID."'>\r\n"; //$hidenform .= "<input type='hidden' name='TotalResult' value='".$this->TotalResult."'>\r\n"; //獲得上一頁(yè)和下一頁(yè)的鏈接 if($this->PageNo != 1) { $prepage.="<li><a href='".$purl."PageNo=$prepagenum'>上一頁(yè)</a></li>\r\n"; $indexpage="<li><a href='".$purl."PageNo=1'>首頁(yè)</a></li>\r\n"; } else { $indexpage="<li><a>首頁(yè)</a></li>\r\n"; } if($this->PageNo!=$totalpage && $totalpage>1) { $nextpage.="<li><a href='".$purl."PageNo=$nextpagenum'>下一頁(yè)</a></li>\r\n"; $endpage="<li><a href='".$purl."PageNo=$totalpage'>末頁(yè)</a></li>\r\n"; } else { $endpage="<li><a>末頁(yè)</a></li>\r\n"; } //獲得數(shù)字鏈接 $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 = ''; if(preg_match('/index/i', $listitem)) $plist .= $indexpage; if(preg_match('/pre/i', $listitem)) $plist .= $prepage; if(preg_match('/pageno/i', $listitem)) $plist .= $listdd; if(preg_match('/next/i', $listitem)) $plist .= $nextpage; if(preg_match('/end/i', $listitem)) $plist .= $endpage; if(preg_match('/option/i', $listitem)) $plist .= $optionlist; if(preg_match('/info/i', $listitem)) $plist .= $maininfo; if($cfg_rewrite == 'Y') { $plist = str_replace('.php?tid=', '-', $plist); $plist = str_replace('&TotalResult=', '-', $plist); $plist = preg_replace("/&PageNo=(\d+)/i",'-\\1.html',$plist); } return $plist; } |
獨(dú)立模型:
/** * 獲取動(dòng)態(tài)的分頁(yè)列表 * * @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頁(yè)/".$this->TotalResult."條記錄</span>"; } if($this->TotalResult == 0) { return "<span class=\"pageinfo\">共0頁(yè)/".$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; //獲得上一頁(yè)和下一頁(yè)的鏈接 if($this->PageNo != 1) { $prepage.="<li><a href='".$purl."PageNo=$prepagenum'>上一頁(yè)</a></li>\r\n"; $indexpage="<li><a href='".$purl."PageNo=1'>首頁(yè)</a></li>\r\n"; } else { $indexpage="<li><a>首頁(yè)</a></li>\r\n"; } if($this->PageNo!=$totalpage && $totalpage>1) { $nextpage.="<li><a href='".$purl."PageNo=$nextpagenum'>下一頁(yè)</a></li>\r\n"; $endpage="<li><a href='".$purl."PageNo=$totalpage'>末頁(yè)</a></li>\r\n"; } else { $endpage="<li><a>末頁(yè)</a></li>"; } //獲得數(shù)字鏈接 $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; } |
仔細(xì)觀察 普通模型中在28行左右的位置多了句$maininfo = "<li><span class=\"pageinfo\">共 <strong>{$totalpage}</strong>頁(yè)<strong>".$this->TotalResult."</strong>條</span></li>\r\n";而在獨(dú)立模型中則沒有。
而且在最后,普通模型中將$maininfo的值加入了$plist
字符串中。(更細(xì)節(jié)的地方是普通模型還判斷了標(biāo)簽中是否有info屬性來(lái)決定是否加入:
if(preg_match('/info/i', $listitem)) $plist .= $maininfo; |
)獨(dú)立模型中這些都省了。
要將獨(dú)立模型修改過(guò)來(lái)很簡(jiǎn)單,不過(guò)“普通模型還判斷了標(biāo)簽中是否有info屬性來(lái)決定是否加入”這點(diǎn)我就不去實(shí)現(xiàn)了,這里不判斷直接再任何情況下都加入maininfo:
/** * 獲取動(dòng)態(tài)的分頁(yè)列表 * * @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頁(yè)/".$this->TotalResult."條記錄</span>"; } if($this->TotalResult == 0) { return "<span class=\"pageinfo\">共0頁(yè)/".$this->TotalResult."條記錄</span>"; } $maininfo = "<li><span class=\"pageinfo\">共 <strong>{$totalpage}</strong>頁(yè)<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; //獲得上一頁(yè)和下一頁(yè)的鏈接 if($this->PageNo != 1) { $prepage.="<li><a href='".$purl."PageNo=$prepagenum'>上一頁(yè)</a></li>\r\n"; $indexpage="<li><a href='".$purl."PageNo=1'>首頁(yè)</a></li>\r\n"; } else { $indexpage="<li><a>首頁(yè)</a></li>\r\n"; } if($this->PageNo!=$totalpage && $totalpage>1) { $nextpage.="<li><a href='".$purl."PageNo=$nextpagenum'>下一頁(yè)</a></li>\r\n"; $endpage="<li><a href='".$purl."PageNo=$totalpage'>末頁(yè)</a></li>\r\n"; } else { $endpage="<li><a>末頁(yè)</a></li>"; } //獲得數(shù)字鏈接 $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; } |
版權(quán)聲明: 本站資源均來(lái)自互聯(lián)網(wǎng)或會(huì)員發(fā)布,如果侵犯了您的權(quán)益請(qǐng)與我們聯(lián)系,我們將在24小時(shí)內(nèi)刪除!謝謝!
轉(zhuǎn)載請(qǐng)注明: dedecms獨(dú)立模型分頁(yè)功能的完善