通常默认dede翻页会从第一页到最后一页展现出来,如果需要按指定需求显示,可以使用我下面的这段代码做参考,include/arc.listview.class.php,这个文件是织梦的文章列表页的翻页管理文件,下面这个是按需求,只显示部分翻页数,此文件包含2个部分的翻页,一个动态浏览的时候的翻页效果,一个静态浏览的翻页效果,需要同时修改。你也可以直接复制我下面给你的翻页代码。
效果如图:
这里一次最多只显示13页,点击>>会展现更多页
参考网址:网页链接
更多的效果,你可以自己看看,这个是我这段时间做的一个项目。
/**
* 获取静态的分页列表
*
* @access public
* @param string $list_len 列表宽度
* @param string $list_len 列表样式
* @return string
*/
function GetPageListST($list_len,$listitem="index,end,pre,next,pageno")
{
$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\">共 <strong>1</strong>页<strong>".$this->TotalResult."</strong>条记录</span></li>\r\n";
}
if($this->TotalResult == 0)
{
//return "<li><span class=\"pageinfo\">共 <strong>0</strong>页<strong>".$this->TotalResult."</strong>条记录</span></li>\r\n";
}
$purl = $this->GetCurUrl();
//$maininfo = "<li><span class=\"pageinfo\">共 <strong>{$totalpage}</strong>页<strong>".$this->TotalResult."</strong>条</span></li>\r\n";
$tnamerule = $this->GetMakeFileRule($this->Fields['id'],"list",$this->Fields['typedir'],$this->Fields['defaultname'],$this->Fields['namerule2']);
$tnamerule = preg_replace("/^(.*)\//", '', $tnamerule);
//获得上一页和主页的链接
if($this->PageNo != 1 && $this->PageNo < 6)
{
$prepage.="<li><a href='".str_replace("{page}",$prepagenum,$tnamerule)."'><<</a></li>\r\n";
//$indexpage="<li><a href='".str_replace("{page}",1,$tnamerule)."'>首页</a></li>\r\n";
}
if($this->PageNo > 5)
{
$prepage.="<li><a href='".str_replace("{page}",$prepagenum,$tnamerule)."'><<</a></li>\r\n";
$indexpage="<li><a href='".str_replace("{page}",1,$tnamerule)."'>首页</a></li>\r\n";
}
//else
//{
//$indexpage="<li>首页</li>\r\n";
//}
//下一页,未页的链接
if($this->PageNo!=$totalpage && $totalpage>1)
{
$nextpage.="<li><a href='".str_replace("{page}",$nextpagenum,$tnamerule)."'>>></a></li>\r\n";
$endpage="<li><a href='".str_replace("{page}",$totalpage,$tnamerule)."'>末页</a></li>\r\n";
}
else
{
//$endpage="<li>末页</li>\r\n";
}
//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";
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";
//获得数字链接
$listdd="";
//$total_list = $list_len * 2 + 1;
$total_list = 13;//显示15个页码
if($this->PageNo >= $total_list)
{
//$j = $this->PageNo-$list_len;
//$total_list = $this->PageNo+$list_len;
$j = $this->PageNo - 6;
$total_list = $this->PageNo + 5;
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\">$j</li>\r\n";
}
else
{
$listdd.="<li><a href='".str_replace("{page}",$j,$tnamerule)."'>".$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;
return $plist;
}
/**
* 获取动态的分页列表
*
* @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 页/".$this->TotalResult." 条记录</span></li>\r\n";
}
if($this->TotalResult == 0)
{
//return "<li><span class=\"pageinfo\">共 0 页/".$this->TotalResult." 条记录</span></li>\r\n";
}
//$maininfo = "<li><span class=\"pageinfo\">共 <strong>{$totalpage}</strong>页<strong>".$this->TotalResult."</strong>条</span></li>\r\n";
$purl = $this->GetCurUrl();
// 如果开启为静态,则对规则进行替换
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";
//获得上一页和下一页的链接
if($this->PageNo != 1 && $this->PageNo < 6)
{
$prepage.="<li><a href='".$purl."PageNo=$prepagenum'><<</a></li>\r\n";
//$indexpage="<li><a href='".$purl."PageNo=1'>首页</a></li>\r\n";
}
if($this->PageNo > 5)
{
$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>\r\n";
}
//获得数字链接
$listdd="";
//$total_list = $list_len * 2 + 1;
$total_list = 13;//显示15个页码
if($this->PageNo >= $total_list)
{
//$j = $this->PageNo-$list_len;
//$total_list = $this->PageNo+$list_len;
$j = $this->PageNo - 6;
$total_list = $this->PageNo + 5;
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;
}