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

支持的靜態(tài)地址如下:www.example.com/xxx-xxx- " /> 国产精品一级,久久久久国产免费免费,呦呦在线视频

色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

php頁碼形式分頁函數(shù)支持靜態(tài)化地址及ajax分頁

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

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

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

其他形式靜態(tài)化需根據(jù)自己情況進(jìn)行改寫

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

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 景东| 滁州市| 桑植县| 新沂市| 民县| 修武县| 璧山县| 惠来县| 郑州市| 桃园县| 湘乡市| 敦化市| 游戏| 兖州市| 仙桃市| 栾川县| 北川| 郯城县| 会昌县| 白河县| 博野县| 娱乐| 英吉沙县| 瑞昌市| 秦皇岛市| 武川县| 科尔| 苏尼特右旗| 唐河县| 庐江县| 黄平县| 吉林市| 武功县| 罗源县| 天全县| 平武县| 时尚| 石泉县| 兴义市| 昭通市| 兰西县|