幫助

pagelist列表分頁標(biāo)簽實(shí)現(xiàn)數(shù)字分頁前后的省略號(hào)

2023-07-10 14:51 易優(yōu)技巧

先上分頁示例圖


實(shí)現(xiàn)教程如下:

1、編輯列表模板,把分頁標(biāo)簽pagelist加上一個(gè)標(biāo)識(shí)pageno,dots,參考代碼

{eyou:pagelist listitem='pre,next,info,index,end,pageno,dots' listsize='1' /}


2、由于每個(gè)模板分頁樣式不同,涉及的分頁php文件官方不會(huì)在線更新覆蓋,請根據(jù)步驟找到分頁php文件補(bǔ)充相關(guān)代碼。

    2.1、用編輯器(非記事本工具)打開文件 core/library/paginator/driver/Eyou.php  (注:Eyou.php為pc分頁文件,手機(jī)端的為:Mobile.php)

    2.2、在108行左右找到代碼  protected function getLinks($listsize = 3)  替換成  protected function getLinks($listsize = 3, $listitemArr = []) 

            

    2.3、把109行大括號(hào) { 開始,到對應(yīng)大括號(hào) } 結(jié)束的代碼進(jìn)行替換

                /**

                *  頁碼按鈕

                * @param string $listsize  當(dāng)前頁對稱兩邊的條數(shù)

                * @return string

                */

                protected function getLinks($listsize  = 3, $listitemArr = [])

                {

                            這里全部代碼都要被替換為2.4步驟的代碼

                }

            替換成以下代碼:

              /**

                *  頁碼按鈕

                * @param string $listsize  當(dāng)前頁對稱兩邊的條數(shù)

                * @return string

                */

              protected function getLinks($listsize = 3, $listitemArr = [])
        {
            if ($this->simple)
                return '';
    
            $block = [
                'first'  => null,
                'slider' => null,
                'last'   => null
            ];
    
            $side   = $listsize;
            $window = $side * 2;
    
            if ($this->lastPage < $window + 2) {
                $block['first'] = $this->getUrlRange(1, $this->lastPage);
            } elseif ($this->currentPage < ($side + 1)) {
                $block['first'] = $this->getUrlRange(1, $window + 1);
            } elseif ($this->currentPage > ($this->lastPage - $side)) {
                $block['last']  = $this->getUrlRange($this->lastPage - $window, $this->lastPage);
            } else {
                $block['slider'] = $this->getUrlRange($this->currentPage - $side, $this->currentPage + $side);
            }
    
            $html = '';
    
            if (is_array($block['first'])) {
                $html .= $this->getUrlLinks($block['first']);
                if (in_array('dots', $listitemArr)) {
                    if ($window + 1 < $this->lastPage) {
                        if ($window + 1 < $this->lastPage - 1) {
                            $html .= $this->getDots();
                        }
                        $html .= $this->getPageLinkWrapper2($this->url($this->lastPage), $this->lastPage);
                    }
                }
            }
    
            if (is_array($block['slider'])) {
                if (in_array('dots', $listitemArr)) {
                    if ($this->currentPage - $side > 1) {
                        $html .= $this->getPageLinkWrapper2($this->url(1), 1);
                        if ($this->currentPage - $side > 2) {
                            $html .= $this->getDots();
                        }
                    }
                }
    
                $html .= $this->getUrlLinks($block['slider']);
    
                if (in_array('dots', $listitemArr)) {
                    if ($this->currentPage + $side < $this->lastPage) {
                        if ($this->currentPage + $side < $this->lastPage - 1) {
                            $html .= $this->getDots();
                        }
                        $html .= $this->getPageLinkWrapper2($this->url($this->lastPage), $this->lastPage);
                    }
                }
            }
    
            if (is_array($block['last'])) {
                if (in_array('dots', $listitemArr)) {
                    if ($this->lastPage - $window < $this->lastPage) {
                        $html .= $this->getPageLinkWrapper2($this->url(1), 1);
                        if ($this->lastPage - $window > 2) {
                            $html .= $this->getDots();
                        }
                    }
                }
                $html .= $this->getUrlLinks($block['last']);
            }
    
            return $html;
        }


    2.4、看下圖找到這個(gè)代碼  array_push($pageArr, $this->getLinks($listsize));   替換成   array_push($pageArr, $this->getLinks($listsize, $listitemArr));

    


    完結(jié)。



QQ在線咨詢