PHPCMS V9自定义栏目伪静态实现方法(列表页/分页
发布时间:2019-12-16 11:14:32作者:admin点击:
首先看urlrewrite的规则,这个是Apache下的,其它环境下的规则自己转换下
RewriteEngine on
#静态文件以及API目录不需要伪静态
RewriteRule ^(statics|api|uploadfile)(.*) – [L]
#内容页
RewriteRule ^([0-9A-Za-z_/]*)/([0-9]+)\.html index.php?m=content&c=index&a=show&dir=$1&id=$2
RewriteRule ^([0-9A-Za-z_/]*)/([0-9]+)_([0-9]+)\.html index.php?m=content&c=index&a=show&dir=$1&id=$2&page=$3
#栏目页
RewriteRule ^([0-9A-Za-z_/]*)/index_([1-9][0-9]*)\.html index.php?m=content&c=index&a=lists&dir=$1&page=$2
RewriteRule ^([0-9A-Za-z_/]*)/ index.php?m=content&c=index&a=lists&dir=$1
1、打开phpcms\modules\content目录下的index.php在最后的}?> 前添加:
/** *根据栏目名获得ID * @param $catdir */
function _getCategoryId($catdir){
$this->category_db = pc_base::load_model('category_model');
$result = $this->category_db->select(array('catdir'=>$catdir));
// print_r($result);
return $result;
}
先增加一个方法,用于将`catdir`转换为`catid`
这是参考站长之家的文章修改而来的,其中获取查询category,我其实一直在纠结是要直接读取cache好还是查询数据库好,读取cache又需要遍历数组,栏目的数量一多的话效率恐怕也没有那么高,增加到 //首页 前面
private function _getCategoryId($catdir){
if(!strpos($catdir,'/')) {
$dirname = $catdir;
}else {
$dirname = end(explode('/',$catdir));
}
$this->category_db = pc_base::load_model('category_model');
$result = $this->category_db->get_one(array('catdir'=>$dirname));
- 上一篇 : WordPress程序手动和自动升级的图文教程
- 下一篇 : ZblogPHP找回管理员密码的3种方法