DISCUZ7.2分页函数

function page($page_num,$cur_page,$per_group,$base_url){  //分页函数参数列表(有多少页,当前页,每页多少个 ,链接地址)
  
     $base_url .= strpos($base_url, '?') ? '&' : '?';
  
     $page_val = "";
  
     if ($page_num < 1) {
         return $page_val;
     } elseif($page_num == 1) {
         return $page_val = 1;
     }
  
     $group_ok = !(($page_num-1)%($per_group-1));
  
     //计算一共有多少组
     if($group_ok) {
         $group_num = ($page_num-1)/($per_group-1);
     } else {
         $group_num = ceil(($page_num-1)/($per_group-1));
     }
  
     //判断当前页是否为一组的最后一个
     $is_last_page = !(($cur_page-1)%($per_group-1));
  
     //计算当前在的组数
     if($is_last_page) {
         $cur_group = ($cur_page-1)/($per_group-1) + 1;
     } else {
         $cur_group = ceil(($cur_page-1)/($per_group-1));
     }
  
     //计算显示的起始页
     $from = ($cur_group - 1) * ($per_group-1) + 1;
     $from = $cur_group <= 1 ? 1 :$from;
     $to = $from + $per_group;
     $to = $to > $page_num ? $page_num + 1 : $to;
  
     for($a = $from; $a < $to; $a++){
         if( $a != $cur_page) {
             $page_val .= '<a href ='.$base_url.'page='.$a.'>'.$a.'</a>';
         } else {
             $page_val .= $a;
         }
     }
  
     //上一页下一页首页尾页
     $next=$cur_page+1;
     $prev=$cur_page-1;
     if ($cur_page!=$page_num) {
         $page_val.='<a href ='.$base_url.'page='.$next.'>'.'下一页'.'</a>';
         $page_val .= '<a href ='.$base_url.'page='.$page_num.'>'.'>>'.'</a>'; //尾页
     }
     if ($cur_page!=1) {
         $page_val = '<a href ='.$base_url.'page='.$prev.'>'.'上一页'.'</a>'.$page_val;
         $page_val = '<a href ='.$base_url.'page=1>'.'<<'.'</a>'.$page_val;  //首页
     }
  
     return $page_val;
 }

你可能感兴趣的:(DISCUZ7.2分页函数)