📄 page.php
字号:
<?php
class Page {
public $total;
public $maxpage;
public $nextpage;
public $page;
public function set($total, $maxpage=null){
$this->total = (int)$total;
$this->page = isset($_GET['page']) ? intval($_GET['page']) : 1; //当前页码e
$this->nextpage = 7;
$this->config = $GLOBALS['config'];
if (is_null($maxpage)){
$this->maxpage = $this->config['maxpage'];
}else{
$this->maxpage = $maxpage;
}
}
/*后台分页*/
public function PrintPage(){
$array = array_merge($_POST,$_GET);
$array['page'] = null;
$array['submit'] = null;
$this->url = null;
if ($array['keyword']){
$array['keyword'] = urlencode(urldecode($array['keyword']));
}else{
$array['keyword'] = null;
}
//print_r($array);
$this->url = INSTALLDIR.'?'.http_build_query($array);
unset($array);
$this->countpage = ceil($this->total / $this->maxpage) ; //总页数
if ($this->countpage == 0){
$this->countpage = 1;
}
if ($this->page > $this->countpage){
$this->page = $this->countpage;
}
$body = '<div class="BlockDof"><div class="pagings"><div class="paging"><a class="total">'.$this->total.'</a><a class="pages">'.$this->page.'/'.$this->countpage.'</a>';
if ($this->page>1){
$body.= '<a class="pages" href="'.$this->url.'&page=1">首页</a><a class="pages" href="'.$this->url.'&page='.($this->page-1).'">上一页</a>';
}
if ($this->countpage < $this->nextpage){
$this->nextpage = $this->countpage;
}
if ($this->page >= $this->nextpage){
$min = floor($this->nextpage /2);
$end = $this->page+$min;
$start = $this->page - floor($this->nextpage /2);
}else{
$start = 1;
$end = $this->nextpage;
}
if ($end > $this->countpage){
$end = $this->countpage;
}
while($start <= $end){
if ($this->page == $start){
$body.= '<a class="pagenow" href="'.$this->url.'&page='.$start.'">'.$start.'</a>';
}else{
$body.= '<a class="page" href="'.$this->url.'&page='.$start.'">'.$start.'</a>';
}
$start++;
}
if ($this->page < $this->countpage){
$body.= '<a class="pages" href="'.$this->url.'&page='.($this->page+1).'">下一页</a>';
$body.= '<a class="pages" href="'.$this->url.'&page='.($this->countpage).'">尾页</a>';
}
$body.= '<a class="input"><input type="text" name="paging_num" value="'.$this->page.'" size="3" style="text-align:center;"> <input type="button" class="btn" value="GO" onclick="javascript:location.href=\''.$this->url.'&page=\'+this.parentNode.firstChild.value;"></a></div></div>';
return $body;
}
public function __set($key, $value){
$this->$key = $value;
}
public function limit(){
$this->pagesize = ($this->page-1) * $this->maxpage;
return ' LIMIT '.$this->pagesize.','.$this->maxpage;
}
/*
前端分页
*/
public function PrintBody(){
$this->url = null;
$array = array_merge($_POST,$_GET);
$array['page'] = null;
$array['submit'] = null;
$this->url = http_build_query($array);
if ($this->config['rewrite'] == 'default' || strtolower($_GET['action']) != 'category'){
$this->url = $this->config['basedir'].'index.php?'.$this->url.'&page={page}';
}else{
$this->url = $this->config['basedir'].str_replace('{id}', $_GET['id'], $this->config['crewrite']);
}
$this->countpage = ceil($this->total / $this->maxpage) ; //总页数
if ($this->countpage == 0){
$this->countpage = 1;
}
if ($this->page > $this->countpage){
$this->page = $this->countpage;
}
$indexpage = str_replace('{page}', 1, $this->url);
if ($this->page>1){
$firstpage = '<li class="home"><a href="'.$indexpage.'">首 页</a></li>';
$pageup= '<li class="previous"><a href="'.str_replace('{page}', ($this->page-1), $this->url).'">上一页</a></li>';
}
if ($this->page<$this->countpage){
$pagedown = '<li class="next"><a href="'.str_replace('{page}', ($this->page+1), $this->url).'">下一页</a></li>';
}
if ($this->page <= ($this->countpage-10)){
$pagedown.= '<li class="next10"><a href="'.str_replace('{page}', ($this->page+10), $this->url).'" title="下十页">下十页</a></li>';
}
if ($this->page != $this->countpage){
$pageover = '<li class="lastly"><a href="'.str_replace('{page}', $this->countpage, $this->url).'">尾 页</a></li>';
}
$body = '<div class="page"><ul><li class="home" ><a href="#" style="width:100px">共'.$this->total.'部/'.$this->countpage.'页</a></li>'.$firstpage.$pageup;
if ($this->countpage<$this->nextpage)
{
$endpage = $this->countpage;
$start = $endpage-$this->nextpage;
}
if ($this->page >= $this->nextpage){
$endpage = $this->page + ceil($this->nextpage/2);
$start = $this->page - ceil($this->nextpage/2);
}else{
$endpage = $this->nextpage;
$start =1;
}
if ($endpage > $this->countpage)
{
$endpage = $this->countpage;
}
if ($start<1) $start = 1;
//echo $start.'='. $endpage;
for($i = $start; $i<=$endpage; $i++){
if ($this->page == $i){
$body.= '<li class="active">'.$i.'</li>';
}else{
$body.= '<li><a href="'.str_replace('{page}', $i, $this->url).'">'.$i.'</a></li>';
}
}
unset($i,$endpage, $cutpage);
$body.= $pagedown.$pageover.'</ul></div>';
return $body;
}
}?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -