Yoho.php 1.91 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 = '';
$html .= '<ul class="pagination pagination-metro pagination-split nomargin">';
if($current > 1)
{
     $html .= '<li><a href="' . $this->getUrl($current - 1) . '"><i class="fa fa-angle-left"></i></a></li>';
}else{
     $html .= '<li class="disabled"><a href="' . $this->getUrl($current - 1) . '"><i class="fa fa-angle-left"></i></a></li>';
}
if ($pageNum > 1) {
	if($pageNum > 5 && $current > 4){

        $html .= '<li><a href="' . $this->getUrl(1) . '">1</a></li>';

		$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 .= '<li><a href="' . $this->getUrl($i) . '">' . $i . '</a></li>';
		}
		else {

            $html .= '<li class="active"><a href="'. $this->getUrl($i) .'">' . $i . '</a></li>';
		}
	}
	if($pageNum > 5 && $pageNum - $current > 3){

        $html .= '<li><a href="' . $this->getUrl($pageNum) . '">' . $pageNum . '</a></li>';
	}
}


if ($current < $pageNum) {
    $html .= '<li><a href="' . $this->getUrl($current + 1) . '"><i class="fa fa-angle-right"></i></a></li>';
}else{
    $html .= '<li class="disabled"><a href="' . $this->getUrl($current + 1) . '"><i class="fa fa-angle-right"></i></a></li>';
}

$html .= '</ul>';
print $html;