<?php $pages = array(); $pageNum = $this->getPageNum(); #总分页数 $current = $this->getCurrent(); #当前页 $size = $this->getSize(); #每页显示数 $total = $this->getTotal(); #获取总数 $pageSetNum = $this->getPageSetSize(); #分页集数 $start = $end = 0; if($current <= 4){ $start = 1; $end = $start + 4; }elseif(($pageNum - $current - 2) > 1) { $start = $current - 2 < 1 ? 1 : $current - 2; $end = $current + 2; }else{ $start = $current - 2; $end = $pageNum; } if($end > $pageNum) { $end = $pageNum; } $startNum = $size * ($current - 1) + 1; $endNum = min($size * $current, $total); $html = ''; if($current > 1) { $html .= '<a href="' . $this->getUrl($current - 1) . '" title="上一页"><span class="ifont10"><</span></a>'; } if ($pageNum > 1) { if($pageNum > 5 && $current > 4){ $html .= '<a href="' . $this->getUrl(1) . '"><span>' . 1 . '</span></a>'; $html .= '<a><span>...</span></a>'; $start = $current - 2; $end = $pageNum - $current <= 3 ? $pageNum : $current + 2; } for ($i = $start; $i <= $end; ++$i) { $_start = $size * ($i - 1) + 1; $_end = min($size * $i, $total); if ($i != $current) { $html .= '<a href="' . $this->getUrl($i) . '"><span>' . $i . '</span></a>'; } else { $html .= '<a href="'. $this->getUrl($i) .'" class="cur"><span>' . $i . '</span></a>'; } } if($pageNum > 5 && $pageNum - $current > 3){ $html .= '<a><span>...</span></a>'; $html .= '<a href="' . $this->getUrl($pageNum) . '"><span>' . $pageNum . '</span></a>'; } } if ($current < $pageNum) { $html .= '<a href="' . $this->getUrl($current + 1) . '" class="page_next" title="下一页"><span class="ifont10">></span></a>'; }