PHPCMS V9自定义栏目伪静态实现方法(列表页/分页/内容页)

首先看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));
                return $result['catid'];
        }
在`show()`方法中,将获取`catid`的语句修改

$catid = intval($_GET['catid']
替换

//$catid = intval($_GET['catid']);
                if(isset ($_GET['catid'])){
                        $catid = intval($_GET['catid']);
                }else{
                        $catid=$this->_getCategoryId($_GET['dir']);
                }
在lists()方法中,将获取’catid’的语句修改

$catid = $_GET[‘catid’] = intval($_GET[‘catid’]);
替换

//$catid = intval($_GET['catid']);
                if(isset ($_GET['catid'])){
                        $catid = intval($_GET['catid']);
                }else{
                        $catid=$this->_getCategoryId($_GET['dir']);
                }
然后在phpcms后台,添加两条自定义的URL规则
URL规则栏目页:{$categorydir}{$catdir}/|{$categorydir}{$catdir}/index_{$page}.html
URL规则内容页: {$categorydir}{$catdir}/{$id}.html|{$categorydir}{$catdir}/{$id}_{$page}.html

找到 //URL规则下面的

$GLOBALS['URL_ARRAY']['categorydir'] = $categorydir;
$GLOBALS['URL_ARRAY']['catdir'] = $catdir;
$GLOBALS['URL_ARRAY']['catid'] = $catid;
替换

$GLOBALS['URL_ARRAY']['categorydir'] = $parentdir;
$GLOBALS['URL_ARRAY']['catdir'] = $catdir;
$GLOBALS['URL_ARRAY']['catid'] = $catid;
2、打开phpcms\modules\content\classes目录中的url.class.php,找到

if (!$setting[‘ishtml’]) { //如果不生成静态
将下面的:

$url = str_replace(array('{$catid}', '{$page}'), array($catid, $page), $urlrule);  
            if (strpos($urls, '\\')!==false) { 
                    $url = APP_PATH.str_replace('\\', '/', $urls);  
            }
替换成:

 
$domain_dir = '';  
            if (strpos($category['url'], '://')!==false && strpos($category['url'], '?')===false) {  
                if (preg_match('/^((http|https):\/\/)?([^\/]+)/i', $category['url'], $matches)) {  
                    $match_url = $matches[0];  
                    $url = $match_url.'/';  
                }  
                $db = pc_base::load_model('category_model');  
                $r = $db->get_one(array('url'=>$url), '`catid`');  
 
                if($r) $domain_dir = $this->get_categorydir($r['catid']).$this->categorys[$r['catid']]['catdir'].'/';  
            }  
            $categorydir = $this->get_categorydir($catid);  
            $catdir = $category['catdir'];  
            $year = date('Y',$time);  
            $month = date('m',$time);  
            $day = date('d',$time);  
            //echo $catdir;  
            $urls = str_replace(array('{$categorydir}','{$catdir}','{$year}','{$month}','{$day}','{$catid}','{$id}','{$prefix}','{$page}'),array($categorydir,$catdir,$year,$month,$day,$catid,$id,$prefix,$page),$urlrule);  
                       // echo $urls."<br />";  
                        if (strpos($urls, '\\')!==false) { 
                    $urls = APP_PATH.str_replace('\\', '/', $urls);  
            }  
                        $url = $domain_dir.$urls;
3、分页问题处理 \phpcms\libs\functions\global.func.php

/**
 * 返回分页路径
 *
 * @param $urlrule 分页规则
 * @param $page 当前页
 * @param $array 需要传递的数组,用于增加额外的方法
 * @return 完整的URL路径
 */
 
function pageurl($urlrule, $page, $array = array()) {
    if(strpos($urlrule, '~')) {
        $urlrules = explode('~', $urlrule);
        $urlrule = $page < 2 ? $urlrules[0] : $urlrules[1];
    }
    $findme = array('{$page}');
    $replaceme = array($page);
    if (is_array($array)) foreach ($array as $k=>$v) {
        $findme[] = '{$'.$k.'}';
        $replaceme[] = $v;
 
    }
 
    $url = str_replace($findme, $replaceme, $urlrule);
    $url = str_replace(array('http://','//','~'), array('~','/','http://'), $url);
    if (!strstr($url,siteurl(get_siteid()))){
                $url = siteurl(get_siteid()) . '/' . $url;
        }
    return $url; 
 
}
然后再更新栏目缓存、批量更新URL就可以看到效果了

时间: 2024-09-20 13:26:57

PHPCMS V9自定义栏目伪静态实现方法(列表页/分页/内容页)的相关文章

筛选-phpcms V9 联动栏目怎么实现

问题描述 phpcms V9 联动栏目怎么实现 类似筛选时联动菜单 做 一个联动栏目的筛选,在筛选到每级栏目的时候显示子栏目下的信息列表,求代码...............谢谢

帝国cms列表内字段内容页刷新不显示

帝国cms列表内字段内容页刷新不显示 删除缓存文件:e /data /tmp

Phpcms V9 网站迁移更换域名方法

网站在发展的过程中,很可能多次的修改域名.那么在Phpcms V9中我们要怎么进行设置呢? 请进行以下步骤的修改: 修改/caches/configs/system.php里面所有和域名有关的,把以前的老域名修改为新域名就可以了. 进行后台设置->站点管理 对相应的站点的域名进行修改. 更新系统缓存.点击后台右上角的"更新缓存"按钮. 进入内容->附件管理->附件地址替换.把附件地址批量的替换为新的地址. 内容->批量更新URL .把所有的文章的地址都更新一下.

Dedecms频道,列表页,内容页中调用全站最新文章

利用dede建站时经常要调用全站的最新文章,本文讲方法总结如下: 1.如果是在首页调用全站的最新文章,标签如下:  代码如下 复制代码 {dede:arclist row=10} <a href="[field:arcurl/]">[field:title/]</a> {/dede:arclist} 2.如果是在频道页列表页调用全站最新文章,标签如下:  代码如下 复制代码 {dede:arclist typeid='top' row='10'} <a h

phpcms v9自定义HTML文件名字的二次开发

1.修改你需要设置的模型,添加一个字段,配置如下:   开发-phpcmsv9二次开发教程"> 2.打开/phpcms/modules/content/create_html.php,找到代码: $urls = $this->url->show($r['id'], '', $r['catid'],$r['inputtime']); 批量替换为: $urls = $this->url->show($r['id'], '', $r['catid'],$r['inputt

phpcms v9屏蔽后台版本更新提示方法总结

方法一 打开phpcms/modules/admin/functions/admin.func.php  代码如下 复制代码 <?php  function system_information($data) {   //$update = pc_base::load_sys_class('update');  //此代码注释即可   //$notice_url = $update->notice();                        //此代码注释即可   $string =

phpcms v9 更新栏目栏目缓存出现PHP has encountered a Stack overflow错误

刚刚给一站更新栏目缓存一个劲的提示PHP has encountered a Stack overflow错误.真折腾人.跟同事交流了下得知之前的栏目被删除了没有更新栏目缓存.随即就更新了一个新的栏目导致错误. 根据得到的情况新一查看v9_category表中有错误信息,删除里面的重复信息即可.还有一个 letter是否有字段空白.删除其即可

Phpcms V9随机文章的调用方法

以下代码只有 order="rand()",其它与正常调用一样.  代码如下 复制代码 {pc:content action="lists" catid="$catid" num="8" order="rand()" return="info"}      <ul class="list lh24 f13">      {loop $info $v}   

织梦dedecms列表页调用所有顶级栏目文章的方法

这几天用织梦做网站,发现了很多问题. 当我们在文章也和文章列表页使用文章调用标签dede:arclist 不限制栏目ID的时候就只会调用当前栏目下的文章,如果是要调用整站的文章发现使用typeid='1,2,3,4,5,6,7,8,9,10' 这样调用出来所有ID的话,当栏目ID很多的话就有些麻烦了!那怎么样可以直接调用织梦CMS整站的文章标签呢 方法一: {dede:arclist row='条数' typeid='all'  orderby='pubdate'}[field:title/]{