emlog分页自定义
[ 2015/06/19, Emlog , 3104阅, 0评 ]

emlog分页自定义.jpg

<?php 
//自定义分页
function pageNavigation($count,$perlogs,$page,$url,$anchor=''){
	$pnums = @ceil($count / $perlogs);
	$page = @min($pnums,$page);
	$prepg = $page-1;
	$nextpg = ($page == $pnums ? 0 : $page+1);
	$urlHome = preg_replace("|[\?&/][^\./\?&=]*page[=/\-]|","",$url);
	$re = "";
	if($pnums<=1){
		return false;
	}
	if($page!=1){
		$re .= "<a href=\"$urlHome$anchor\">首页</a>";
	}
	if($prepg){
		$re .= "<a href=\"$url$prepg$anchor\">上一页</a>";
	}
	for($i = $page-2;$i <= $page+2 && $i <= $pnums; $i++){
		if ($i > 0){
			if ($i == $page){
				$re .= "<span>$i</span>";
			}elseif($i == 1){
				$re .= "<a href=\"$urlHome$anchor\">$i</a>";
			}else{
				$re .= "<a href=\"$url$i$anchor\">$i</a>";
			}
		}
	}
	if($nextpg){
		$re .= "<a href=\"$url$nextpg$anchor\">下一页</a>";
	}
	if($page!=$pnums){
		$re .= "<a href=\"$url$pnums$anchor\" title=\"尾页\">尾页</a>";
	}
	$re .= " 跳转到第 <select name='topage' size='1' onchange='window.location=\"$url\"+this.value'>\n";
	for($i=1;$i<=$pnums;$i++){
		if($i==$page){
			$re .= "<option value='$i' selected>$i</option>\n";
		}else{
			$re .= "<option value='$i'>$i</option>\n";
		}
	}
	$re .= "</select> 页,共 $pnums 页";
	return $re;
}?>

log_list.php页调用:

<?php echo pageNavigation($lognum,$index_lognum,$page,$pageurl);?>

t.php页调用

<?php echo pageNavigation($twnum,Option::get('index_twnum'),$page,BLOG_URL.'t/?page=');?>

有朋自远方来...评论一下呗O(∩_∩)O