目前此分頁支持靜態化地址分頁和無鏈接地址時的ajax分頁(但是js得自己寫):

支持的靜態地址如下:www.example.com/xxx-xxx- " /> 国产成人咱精品视频免费网站,色多网站免费视频,日韩不卡一二三区

一区二区久久-一区二区三区www-一区二区三区久久-一区二区三区久久精品-麻豆国产一区二区在线观看-麻豆国产视频

php頁碼形式分頁函數支持靜態化地址及ajax分頁

之前每次遇到分頁,總是得自己寫,覺得挺繁瑣的,所以本著通用的原則,寫了一個分頁的方法,特此記錄。

目前此分頁支持靜態化地址分頁和無鏈接地址時的ajax分頁(但是js得自己寫):

支持的靜態地址如下:www.example.com/xxx-xxx-p1-xxxx-xx.html

其他形式靜態化需根據自己情況進行改寫

支持ajax方式分頁時,$link參數為空,但提供了pid和optype,其中pid用于獲取該頁碼頁數,optype用于一個頁面存在多個分頁時區分當前觸發動作屬于哪個分頁邏輯
復制代碼 代碼如下:
/**********************************************************
*
* 獲取頁碼
*
**********************************************************
*
* @params string $link 鏈接地址(鏈接為空時可以用ajax翻頁)
*
* @params int $intPage 當前頁數
*
* @params int $intTotal 總頁數
*
* @params int $intSize 要顯示的頁數個數
*
* @params string $type 鏈接種類(多個翻頁用于區分翻頁區域)
*
**********************************************************
*
* @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>';
//窗口寬度大于等于總頁數
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技術php頁碼形式分頁函數支持靜態化地址及ajax分頁,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 久久99网站| 日韩在线资源 | 免费一级特黄欧美大片勹久久网 | 一区二区三区四区精品 | 91精品福利老司机在线观看 | 激情五月五月婷婷 | 亚洲精品国产精品国自产 | 久久综合九色婷婷97 | 91精品国产综合成人 | 伊人久久综在合线亚洲91 | 国产91精品在线观看 | 国产精品永久免费视频观看 | 国产亚洲欧洲精品 | 久久青草免费97线频观 | 激情丁香小说 | 成人免费观看在线网址 | 日本精品久久久一区二区三区 | 亚洲色图视频在线观看 | 四虎影视国产精品永久在线 | 久久综合精品国产一区二区三区 | 黄色片在线观看网站 | 中文字幕一区二区三区在线播放 | 香蕉人人超人人超免费看视频 | 国产swag在线观看 | 欧美成人在线视频 | 91精品综合国产在线观看 | 成年美女黄| 香蕉eeww99国产在线观看 | 真人视频一级毛片 | 国产区二区 | 国产精品美女久久久久网 | wwwwwww黄| 亚洲人6666成人观看 | 99福利| 色婷丁香 | 国产精品短篇二区 | 国产免费成人在线视频 | 国产精品 主播精选 网红 | 亚洲国产夜色在线观看 | 天天干天天干天天干 | 日韩老女人 |