新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷(xiāo)解決方案
PHP自定義帶省略號(hào)的分頁(yè)類(lèi)
有時(shí)候框架提供的分頁(yè)類(lèi),不能夠滿(mǎn)足我們的需求,這個(gè)時(shí)候就需要進(jìn)行自定義分頁(yè)類(lèi)來(lái)實(shí)現(xiàn)分頁(yè)了

pageno = ceil($total / $pagesize);
$this->url = $url;
$this->maxpageno = $maxpageno < 7 ? 7 : $maxpageno;
}
//分頁(yè)
function render($curpage = 1, $curclass = 'active')
{
if ($pos = strrpos($this->url, '.')) {
$this->suffix = substr($this->url, $pos);
$this->url = substr($this->url, 0, $pos);
}
//上頁(yè)下頁(yè)
$pre_url = $next_url = 'javascript:;';
if ($curpage > 1) {
$pre_url = $this->url . ($curpage - 1) . $this->suffix;
}
if ($curpage < $this->pageno) {
$next_url = $this->url . ($curpage + 1) . $this->suffix;
}
//省略
if ($this->pageno > $this->maxpageno) {
$half = floor(($this->maxpageno - 4) / 2);
$half_start = $curpage - $half + 1;
if ($this->maxpageno % 2 !== 0) --$half_start;
$half_end = $curpage + $half;
}
if (($this->pageno - $curpage) < ($this->maxpageno - 3)) {
$half_start = $this->pageno - $this->maxpageno + 3;
unset($half_end);
}
if ($curpage <= ($this->maxpageno - 3)) {
$half_end = $this->maxpageno - 2;
unset($half_start);
}
if ($curpage == 1) {
$page = $this->getpage($pre_url, ' class="disabled"', '上一頁(yè)');
} else {
$page = $this->getpage($pre_url, '', '上一頁(yè)');
}
for ($i = 1; $i <= $this->pageno; $i++) {
if (isset($half_start) && $i < $half_start && $i > 1) {
if ($i == 2) $page .= $this->getpage('javascript:;', ' class="disabled"', '...');
continue;
}
if (isset($half_end) && $i > $half_end && $i < $this->pageno) {
if ($i == ($half_end + 1)) $page .= $this->getpage('javascript:;', ' class="disabled"', '...');
continue;
}
if ($i == $curpage) {
$in = " class='{$curclass}'";
$url = 'javascript:;';
} else {
$in = '';
$url = $this->url . $i . $this->suffix;
}
$page .= $this->getpage($url, $in, $i);
}
if ($curpage == $this->pageno) {
$page .= $this->getpage($next_url, ' class="disabled"', '下一頁(yè)');
} else {
$page .= $this->getpage($next_url, '', '下一頁(yè)');
}
return sprintf(
'%s
',
$page
);
}
private function getpage($url, $class, $i)
{
if ($url == 'javascript:;') {
return "{$i} ";
} else {
return "{$i} ";
}
}
}
$curpage = isset($_GET['page']) ? $_GET['page'] : 1;
$page = new Pager(35, 2, '?page=');
?>
動(dòng)態(tài)分頁(yè):
=$page->pagelist($curpage)?>
靜態(tài)分頁(yè),看url:
url = '/html/news/list_.html';
echo $page->pagelist($curpage);
?>
CSS樣式
.pagination{text-align: center; margin-top: 35px;}
.pagination a, .pagination span{padding: 3px 10px; background: #e8eaeb; display: inline-block; text-align: center; line-height: 25px; color: #818181; font-size: 14px}
.pagination a:hover, .pagination .fenye-on, .pagination li.active span{background: #0395D5 !important; color: #fff !important}
.pagination li{display: inline-block;margin: 0 5px;}
.pagination li.disabled span{cursor: no-drop; background: #f7f7f7; color: #ccc;}
圖片
以上這篇PHP自定義帶省略號(hào)的分頁(yè)類(lèi)就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持創(chuàng)新互聯(lián)。
網(wǎng)站名稱(chēng):PHP自定義帶省略號(hào)的分頁(yè)類(lèi)
本文路徑:http://fisionsoft.com.cn/article/cocjioj.html


咨詢(xún)
建站咨詢(xún)
