Yoho.php 1.65 KB
<?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) . '" class="page_pre" title="上一页"><span class="iconfont">&#xe634;</span>上一页</a>';
}
if ($pageNum > 1) {
	if($pageNum >= 5 && $current > 4){
		$html .= '<a href="' . $this->getUrl(1) . '">' . 1 . '</a>';
		$html .= '<a>...</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) . '">' . $i . '</a>';
		}else {
			$html .= '<a href="'. $this->getUrl($i) .'" class="cur">' . $i . '</a>';
		}
	}
	if($pageNum > 5 && $pageNum - $current > 3){
		$html .= '<a>...</a>';
		$html .= '<a href="' . $this->getUrl($pageNum) . '">' . $pageNum . '</a>';
	}
}
if ($current < $pageNum) {
	$html .= '<a href="' . $this->getUrl($current + 1) . '" title="下一页">下一页<span class="iconfont">&#xe601;</span></a>';
}
$html .= '';