php 代码:
$page = empty($_GET['page'])?1:$_GET['page'];$relation = $this->termRelationships($termId,$page,$termLimit);
$data = $relation['data'];
if(empty($data)){
redirect('/index.php');
}
$data = $relation['data'];
//数据总数
$count = $relation['count'];
//页数
$pageNum = ceil($count/$termLimit);
//上一页
$prePage = $page-1;
//下一页
$nextPage = $page+1;
if(!empty($data)){
$model = M('Posts');
foreach($data as $value){
$object_id = $value['object_id'];
$temp = $model->find($object_id);
$temp['post_date'] = date('m-d',strtotime($temp['post_date']));
$dataArr[] = $temp;
}
}
$this->assign('pre',$prePage);
$this->assign('next',$nextPage);
$this->assign('nowPage',$page);
$this->assign('page',$pageNum+1);
$this->assign('count',$pageNum);
$this->assign('data',$dataArr);
模版中的代码:
<div class="pag">
<a href="{:U('share/index')}">首页</a>
<if condition="$pre gt 0">
<a href="{:U('share/index',array('page'=>$pre))}">上一页</a>
<else/>
<a href="javascript:;">上一页</a>
</if>
<for start="1" end="$page">
<if condition="$i eq $nowPage">
<a class="p_hov" href="javascript:;">{$i}</a>
<else/>
<a href="{:U('share/index',array('page'=>$i))}">{$i}</a>
</if>
</for>
<if condition="$next lt $page">
<a href="{:U('share/index',array('page'=>$next))}">下一页</a>
<else/>
<a href="javascript:;">下一页</a>
</if>
<if condition="$nowPage eq $count">
<a href="javascript:;">末页</a>
<else/>
<a href="{:U('share/index',array('page'=>$count))}">末页</a>
</if>
</div>