OneThink框架的文章详情页分页

Application/Home/Controller/ArticleController.class.php的detail函数修改结果如下:

/* 文档模型详情页 */
public function detail($id = 0, $p = 1){
/* 标识正确性检测 */
if(!($id && is_numeric($id))){
$this->error('文档ID错误!');
}

/* 页码检测 */
$p = intval($p);
$p = empty($p) ? 1 : $p;

/* 获取详细信息 */
$Document = D('Document');
$info = $Document->detail($id);
if(!$info){
$this->error($Document->getError());
}
$content_array=explode('##分页##',$info['content']);
if(count($content_array)>1){
$info['content']=$content_array[$p-1];
$parse="";
for($i=1;$i<=count($content_array);$i++){
$parse.="<li><a href=".U('Article/detail',array('id'=>$info['id'],'page'=>$i)).">".$i."</a></li>";
}
$this->assign('page_string',$parse);
}

/* 分类信息 */
$category = $this->category($info['category_id']);

/* 获取模板 */
if(!empty($info['template'])){//已定制模板
$tmpl = $info['template'];
} elseif (!empty($category['template_detail'])){ //分类已定制模板
$tmpl = $category['template_detail'];
} else { //使用默认模板
$tmpl = 'Article/'. get_document_model($info['model_id'],'name') .'/detail';
}

/* 更新浏览数 */
$map = array('id' => $id);
$Document->where($map)->setInc('view');

/* 模板赋值并渲染模板 */
$this->assign('category', $category);
$this->assign('info', $info);
$this->assign('page', $p); //页码
$this->display($tmpl);
}

在后台添加文章的时候,在需要分页的地方插入   ##分页##

视图部分分页代码为:

<div class="pagination">
<ul>
{$page_string}
</ul>
</div>

基本思路:是把文章的content字段内容,分割为数组元素,根据传入p参数值的不同,显示数组不同的元素。

原文地址:https://www.cnblogs.com/shanmao/p/4940722.html