QQ咨询 官方微信

添加微信好友

官方小程序

百度小程序

微信小程序

头条小程序

关于我们

PHPCMS

PHPCMS V9自定义栏目伪静态实现方法

 admin  2024-02-27 16:09:10
phpcmsV9栏目伪静态的修改方法(支持自定义目录名),官方程序默认伪静态是不支持自定义栏目名的,所以今天就做了以下修改,让其支持!
首先看urlrewrite的规则,这个是IIS6下的,其它环境下的规则自己转换下
  1. RewriteRule /phpcms/(.*)(.*)/ /phpcms/index\.php\?m=contentc=indexa=listscategorydir=$1catdir=$2   
  2. RewriteRule /phpcms/(.*)(.*)/([0-9]+)/ /phpcms/index\.php\?m=contentc=indexa=listscategorydir=$1catdir=$2page=$3  
  1、打开phpcms\modules\content目录下的index.php找到 public function lists() {,将$catid = intval($_GET['catid']);替换成:
  1. if(isset ($_GET['catid'])){   
  2.                     $catid = intval($_GET['catid']);   
  3.                 }else{   
  4.                     $catdir=$_GET['catdir'];   
  5.                     if($catdir==""){   
  6.                         $catdir=$_GET['categorydir'];   
  7.                     }   
  8.                     $s=$this->_getCategoryId($catdir);   
  9.                     $catid=$s[0][catid];                      
  10.                 }  

并且在最后的}?> 前添加:
  1. /**  
  2.          *根据栏目名获得ID  
  3.          * @param <type> $catdir  
  4.          */  
  5.         function _getCategoryId($catdir){   
  6.             $this->category_db = pc_base::load_model('category_model');   
  7.             $result = $this->category_db->select(array('catdir'=>$catdir));   
  8.            // print_r($result);   
  9.             return $result;   
  10.          }  
 2、打开phpcms\modules\content\classes目录中的url.class.php,找到
  1. if (!$setting['ishtml']) { //如果不生成静态 
  将下面的:
  1. $url = str_replace(array('{$catid}''{$page}'), array($catid, $page), $urlrule);   
  2.             if (strpos($urls, '\\')!==false) {  
  3.                     $url = APP_PATH.str_replace('\\', '/', $urls);   
  4.             }   
替换成:
  1. $domain_dir = '';   
  2.             if (strpos($category['url'], '://')!==false && strpos($category['url'], '?')===false) {   
  3.                 if (preg_match('/^((http|https):\/\/)?([^\/]+)/i', $category['url'], $matches)) {   
  4.                     $match_url = $matches[0];   
  5.                     $url = $match_url.'/';   
  6.                 }   
  7.                 $db = pc_base::load_model('category_model');   
  8.                 $r = $db->get_one(array('url'=>$url), '`catid`');   
  9.   
  10.                 if($r) $domain_dir = $this->get_categorydir($r['catid']).$this->categorys[$r['catid']]['catdir'].'/';   
  11.             }   
  12.             $categorydir = $this->get_categorydir($catid);   
  13.             $catdir = $category['catdir'];   
  14.             $year = date('Y',$time);   
  15.             $month = date('m',$time);   
  16.             $day = date('d',$time);   
  17.             //echo $catdir;   
  18.             $urls = str_replace(array('{$categorydir}','{$catdir}','{$year}','{$month}','{$day}','{$catid}','{$id}','{$prefix}','{$page}'),array($categorydir,$catdir,$year,$month,$day,$catid,$id,$prefix,$page),$urlrule);   
  19.                        // echo $urls."<br>";   
  20.                         if (strpos($urls, '\\')!==false) {  
  21.                     $urls = APP_PATH.str_replace('\\', '/', $urls);   
  22.             }   
  23.                     $url = $domain_dir.$urls; 

3、后台URL规则中添加:
  1. url示例:1/   
  2. url规则:{$categorydir}{$catdir}/|{$categorydir}{$catdir}/{$page}/  

  更新栏目缓存就OK了。
¥ 打赏
×
如果您觉得文章帮助了您就打赏一下吧
非常感谢你的打赏,我们将继续分享更多优质内容,让我们一起创建更加美好的网络世界!

支付宝扫一扫打赏

微信扫一扫打赏

本文《PHPCMS V9自定义栏目伪静态实现方法》发布于石头博客文章,作者:admin,如若转载,请注明出处:https://www.pweb123.com/cms/phpcms/709.html,否则禁止转载,谢谢配合!

文章点评

我来说两句 已有0条评论
点击图片更换

添加微信好友

添加微信好友

微信小程序

百度小程序