pagelist列表分页标签实现数字分页前后的省略号-j9九游

2023-07-10 14:51 易优技巧

先上分页示例图


实现教程如下:

1、编辑列表模板,把分页标签pagelist加上一个标识pageno,dots,参考代码

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


2、由于每个模板分页样式不同,涉及的分页php文件官方不会在线更新覆盖,请根据步骤找到分页php文件补充相关代码。

    2.1、用编辑器(非记事本工具)打开文件 core/library/paginator/driver/eyou.php  (注:eyou.php为pc分页文件,手机端的为:mobile.php)

    2.2、在108行左右找到代码  protected function getlinks($listsize = 3)  替换成  protected function getlinks($listsize = 3, $listitemarr = []) 

            

    2.3、把109行大括号 { 开始,到对应大括号 } 结束的代码进行替换

                /**

                *  页码按钮

                * @param string $listsize  当前页对称两边的条数

                * @return string

                */

                protected function getlinks($listsize  = 3, $listitemarr = [])

                {

                            这里全部代码都要被替换为2.4步骤的代码

                }

            替换成以下代码:

              /**

                *  页码按钮

                * @param string $listsize  当前页对称两边的条数

                * @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->, $this->lastpage);
                    }
                }
            }
    
            if (is_array($block['slider'])) {
                if (in_array('dots', $listitemarr)) {
                    if ($this->currentpage - $side > 1) {
                        $html .= $this->getpagelinkwrapper2($this->, 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->, $this->lastpage);
                    }
                }
            }
    
            if (is_array($block['last'])) {
                if (in_array('dots', $listitemarr)) {
                    if ($this->lastpage - $window < $this->lastpage) {
                        $html .= $this->getpagelinkwrapper2($this->, 1);
                        if ($this->lastpage - $window > 2) {
                            $html .= $this->getdots();
                        }
                    }
                }
                $html .= $this->geturllinks($block['last']);
            }
    
            return $html;
        }


    2.4、看下图找到这个代码  array_push($pagearr, $this->getlinks($listsize));   替换成   array_push($pagearr, $this->getlinks($listsize, $listitemarr));

    


    完结。



    微信客服

    工作日 8:30-12:00 14:30-18:30

网站地图