|
目前此分頁(yè)支持靜態(tài)化地址分頁(yè)和無(wú)鏈接地址時(shí)的ajax分頁(yè)(但是js得自己寫):
支持的靜態(tài)地址如下:www.example.com/xxx-xxx-p1-xxxx-xx.html
其他形式靜態(tài)化需根據(jù)自己情況進(jìn)行改寫
支持ajax方式分頁(yè)時(shí),$link參數(shù)為空,但提供了pid和optype,其中pid用于獲取該頁(yè)碼頁(yè)數(shù),optype用于一個(gè)頁(yè)面存在多個(gè)分頁(yè)時(shí)區(qū)分當(dāng)前觸發(fā)動(dòng)作屬于哪個(gè)分頁(yè)邏輯
復(fù)制代碼 代碼如下:
/**********************************************************
*
* 獲取頁(yè)碼
*
**********************************************************
*
* @params string $link 鏈接地址(鏈接為空時(shí)可以用ajax翻頁(yè))
*
* @params int $intPage 當(dāng)前頁(yè)數(shù)
*
* @params int $intTotal 總頁(yè)數(shù)
*
* @params int $intSize 要顯示的頁(yè)數(shù)個(gè)數(shù)
*
* @params string $type 鏈接種類(多個(gè)翻頁(yè)用于區(qū)分翻頁(yè)區(qū)域)
*
**********************************************************
*
* @return array
*/
private function formatPage($link="",$intPage,$intTotal,$intSize=3,$type="")
{
$strPage = '<div class="g_serpage clearfix">';
if($intTotal > 0)
{
if($intPage > 1)
$strPage .= $link!=''?'<a href="'.preg_replace("/-p(/d+)/","p".($intPage-1),$link).'"><<</a>':'<a optype="'.$type.'" pid="showpage_'.($intPage-1).'" href="Javascript:void(0)"><<</a>';
else
$strPage .= '<a href="Javascript:void(0)"><<</a>';
//窗口寬度大于等于總頁(yè)數(shù)
if( ($intSize+2) >= $intTotal )
{
for($i=1;$i<=$intTotal;$i++)
{
$strClass = $i == $intPage ? 'class="g_serpagcur"' : "";
$strPage .= $link!=''?'<a href="'.preg_replace("/-p(/d+)/","p".$i,$link).'" '.$strClass.'>'.$i.'</a>':'<a optype="'.$type.'" pid="showpage_'.$i.'" href="Javascript:void(0)" '.$strClass.'>'.$i.'</a>';
}
}
else
{
if($intPage < ceil($intSize/2))
{
for($i=1;$i<=$intSize;$i++)
{
$strClass = $i == $intPage ? 'class="g_serpagcur"' : "";
$strPage .= $link!=''?'<a href="'.preg_replace("/-p(/d+)/","p".$i,$link).'" '.$strClass.'>'.$i.'</a>':'<a optype="'.$type.'" pid="showpage_'.$i.'" href="Javascript:void(0)" '.$strClass.'>'.$i.'</a>';
}
$strPage .= $link!=''?'<a class="gpage_nobor" >…</a><a href="'.preg_replace("/-p(/d+)/","p".$intTotal,$link).'" >'.$intTotal.'</a>':'<a class="gpage_nobor" >…</a><a optype="'.$type.'" pid="showpage_'.$intTotal.'" href="Javascript:void(0)" >'.$intTotal.'</a>';
}
elseif(($intTotal-$intPage) < ceil($intSize/2))
{
$strPage .= $link!=''?'<a href="'.preg_replace("/-p(/d+)/","p1",$link).'">1</a><a class="gpage_nobor" >…</a>':'<a optype="'.$type.'" pid="showpage_1" href="Javascript:void(0)">1</a><a class="gpage_nobor" >…</a>';
for($i = ($intTotal + 1 - $intSize);$i++;$i<=$intTotal)
{
$strClass = $i == $intPage ? 'class="g_serpagcur"' : "";
$strPage .= $link!=''?'<a href="'.preg_replace("/-p(/d+)/","p".$i,$link).'" '.$strClass.'>'.$i.'</a>':'<a optype="'.$type.'" pid="showpage_'.$i.'" href="Javascript:void(0)" '.$strClass.'>'.$i.'</a>';
}
}
else
{
$intOffset = floor($intSize/2);
$strPage .= $link!=''?'<a href="'.preg_replace("/-p(/d+)/","p1",$link).'">1</a>':'<a optype="'.$type.'" pid="showpage_1" href="Javascript:void(0)">1</a>';
if( ($intPage - $intOffset) > 2)
{
$strPage .= '<a class="gpage_nobor" >…</a>';
}
for($i=(($intPage - $intOffset)<=1?2:($intPage - $intOffset));$i<=(($intPage + $intOffset)>=$intTotal?($intTotal-1):($intPage + $intOffset));$i++)
{
$strClass = $i == $intPage ? 'class="g_serpagcur"' : "";
$strPage .= $link!=''?'<a href="'.preg_replace("/-p(/d+)/","p".$i,$link).'" '.$strClass.'>'.$i.'</a>':'<a optype="'.$type.'" pid="showpage_'.$i.'" href="Javascript:void(0)" '.$strClass.'>'.$i.'</a>';
}
if( ($intPage - $intOffset) < ($intTotal - 1))
{
$strPage .= '<a class="gpage_nobor" >…</a>';
}
$strPage .= $link!=''?'<a href="'.preg_replace("/-p(/d+)/","p".$intTotal,$link).'">'.$intTotal.'</a>':'<a optype="'.$type.'" pid="showpage_'.$intTotal.'" href="Javascript:void(0)">'.$intTotal.'</a>';
}
}
if($intPage < $intTotal)
{
$strPage .= $link!=''?'<a href="'.preg_replace("/-p(/d+)/","p".($intPage+1),$link).'">>></a>':'<a optype="'.$type.'" pid="showpage_'.($intPage+1).'" href="Javascript:void(0)">>></a>';
}
else
{
$strPage .= '<a href="Javascript:void(0)">>></a>';
}
}
$strPage .= "</div>";
return $strPage;
}
php技術(shù):php頁(yè)碼形式分頁(yè)函數(shù)支持靜態(tài)化地址及ajax分頁(yè),轉(zhuǎn)載需保留來(lái)源!
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。