在线咨询
微信咨询
服务热线
服务热线:15639912513
TOP
当前位置:
首页 > 新闻中心> PHP课堂>thinkphp5分页怎么设置显示页码数量

thinkphp5分页怎么设置显示页码数量

发布时间:2019-07-11 浏览:5789次

兴弘海科技在制作高端网站定制类型的网站的时候,遇到了列表显示页码数量的问题。

thinkphp自带的列表页码数量是10个,可是客户嫌页码数量太多,于是在经过一番斟酌后。关于分页页码数量的问题解决了。以下是代码。可以直接使用。

protected function getLinks()
{
   if ($this->simple)
       return '';

   $block = [
       'first'  => null,
       'slider' => null,
       'last'   => null
   ];

   $side   = 2;
   $window = $side * 2;

   if ($this->lastPage < $window +1) {
       $block['slider'] = $this->getUrlRange(1, $this->lastPage);

   } elseif ($this->currentPage <= $window-1) {

       $block['slider'] = $this->getUrlRange(1, $window + 1);
   } elseif ($this->currentPage > ($this->lastPage - $window+1)) {
       $block['slider']  = $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 (is_array($block['slider'])) {

       $html .= $this->getUrlLinks($block['slider']);
   }

   if (is_array($block['last'])) {
       $html .= $this->getUrlLinks($block['last']);
   }

   return $html;
}

以上代码直接复制到相应的php文件就可以出现最多5个页码。

TAG
5789
该内容对我有帮助