php 分页中间省略

/**
     * [page description]  分页
     * @param  [type] $sum     [总页数]
     * @param  [type] $pagenum [页数]
     * @return [type]          [description]
     */
    function page($sum,$pagenum,$href){
        $span = "";
        if($sum > 0){
              if($pagenum <=0){$pagenum = 1;}
              if($pagenum >= $sum){$pagenum = $sum;}

              $k = $pagenum-1 <= 0 ? 1:$pagenum-1;
              $m = $sum - 6 <= 0 ?1:$sum-6;
              $pageM = $pagenum == 1?$pagenum+2:$pagenum + 1;

              if($sum - $pagenum >= 6){
                  for($i = $k; $i <= $pageM; $i++){
                      $color = $i == $pagenum?'style="background:#2d8cf0;color:white"':'';
                      $span .= "<a href='{$href}{$i}' {$color}>{$i}</a>";
                  }
                  $span .= '....';
                  for($i = $sum - 3; $i <= $sum; $i++){
                      $span .= "<a href='{$href}{$i}'>{$i}</a>";
                  }
              }else{
                  for($i = $m; $i <= $sum; $i++){
                      $color = $i == $pagenum?'style="background:#2d8cf0;color:white"':'';
                      $span .= "<a href='{$href}{$i}'  {$color}>{$i}</a>";
                  }
              }
          }
          return $span;
    }

 

posted @ 2020-11-02 15:03  时间掉飞机  阅读(211)  评论(0编辑  收藏  举报