日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
PHP自定義帶省略號的分頁類

有時候框架提供的分頁類,不能夠滿足我們的需求,這個時候就需要進(jìn)行自定義分頁類來實現(xiàn)分頁了

pageno = ceil($total / $pagesize);
        $this->url = $url;
        $this->maxpageno = $maxpageno < 7 ? 7 : $maxpageno;
    }

    //分頁
    function render($curpage = 1, $curclass = 'active')
    {
        if ($pos = strrpos($this->url, '.')) {
            $this->suffix = substr($this->url, $pos);
            $this->url = substr($this->url, 0, $pos);
        }
        //上頁下頁
        $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"', '上一頁');
        } else {
            $page = $this->getpage($pre_url, '', '上一頁');
        }

        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"', '下一頁');
        } else {
            $page .= $this->getpage($next_url, '', '下一頁');
        }

        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='); ?>

動態(tài)分頁:

pagelist($curpage)?>

靜態(tài)分頁,看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自定義帶省略號的分頁類就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持創(chuàng)新互聯(lián)。


文章標(biāo)題:PHP自定義帶省略號的分頁類
網(wǎng)站地址:http://www.dlmjj.cn/article/cocjioj.html