《CMS技巧:簡單的PHPCMS V9自定義欄目偽靜態實現方法》要點:
本文介紹了CMS技巧:簡單的PHPCMS V9自定義欄目偽靜態實現方法,希望對您有用。如果有疑問,可以聯系我們。
相關主題:PHPCMS教程
CMS技巧 首先看urlrewrite的規則,這個是IIS6下的,其它環境下的規則自己轉換下
CMS技能 RewriteRule /phpcms/(.*)(.*)/ /phpcms/index.php?m=contentc=indexa=listscategorydir=$1catdir=$2 RewriteRule /phpcms/(.*)(.*)/([0-9]+)/ /phpcms/index.php?m=contentc=indexa=listscategorydir=$1catdir=$2page=$3
CMS技能 1、打開phpcmsmodulescontent目錄下的index.php找到 public function lists() {,將$catid = intval($_GET['catid']);替換成:
CMS技能 if(isset ($_GET['catid'])){ $catid = intval($_GET['catid']); }else{ $catdir=$_GET['catdir']; if($catdir==""){ $catdir=$_GET['categorydir']; } $s=$this->_getCategoryId($catdir); $catid=$s[0][catid]; }
CMS技巧 而且在最后的}?> 前添加:
CMS技巧 /** *根據欄目名得到ID * @param <type> $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; }
CMS技能 2、打開phpcmsmodulescontentclasses目錄中的url.class.php,找到
CMS技能 if (!$setting['ishtml']) { //如果不生成靜態
CMS技能 將下面的:
CMS技能 $url = str_replace(array('{$catid}', '{$page}'), array($catid, $page), $urlrule); if (strpos($urls, '')!==false) { $url = APP_PATH.str_replace('', '/', $urls); }
CMS技能 替換成:
CMS技能 $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;
CMS技巧 3、后臺URL規矩中添加:
CMS技巧 url示例:1/ url規矩:{$categorydir}{$catdir}/|{$categorydir}{$catdir}/{$page}/
CMS技能 更新欄目緩存就OK了.
維易PHP培訓學院每天發布《CMS技巧:簡單的PHPCMS V9自定義欄目偽靜態實現方法》等實戰技能,PHP、MYSQL、LINUX、APP、JS,CSS全面培養人才。
轉載請注明本頁網址:
http://www.snjht.com/jiaocheng/8909.html