QQ咨询 官方微信

添加微信好友

官方小程序

百度小程序

微信小程序

头条小程序

关于我们

PHPCMS

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

 admin  2022-06-03 19:31:31
1、打开phpcms\modules\content目录下的index.php在最后的}?> 前添加:
  1. private function _getCategoryId($catdir){  
  2.                 if(!strpos($catdir,'/')) {  
  3.                         $dirname = $catdir;  
  4.                 }else {  
  5.                         $dirname = end(explode('/',$catdir));  
  6.                 }  
  7.                 $this->category_db = pc_base::load_model('category_model');  
  8.                 $result = $this->category_db->get_one(array('catdir'=>$dirname));  
  9.                 return $result['catid'];  
  10.         }  

增加一个方法,用于将`catdir`转换为`catid`
然后在`show()`方法中,将获取`catid`的语句修改,大概35行找到:
  1. $catid = intval($_GET['catid']  
改成:
  1. if(isset ($_GET['catid'])){  
  2.          $catid = intval($_GET['catid']);  
  3. }else{  
  4.           $catid=$this->_getCategoryId($_GET['dir']);  
  5. }  
然后在在lists()方法中找到207行,将获取’catid’的语句修改
  1. $catid = $_GET[‘catid’] = intval($_GET[‘catid’]);  
改成:
  1. if(isset ($_GET['catid'])){  
  2.           $catid = intval($_GET['catid']);  
  3. }else{  
  4.            $catid=$this->_getCategoryId($_GET['dir']);  
  5. }  
然后找到大概260行:
  1. $GLOBALS['URL_ARRAY']['categorydir'] = $categorydir;  
  2. $GLOBALS['URL_ARRAY']['catdir'] = $catdir;  
  3. $GLOBALS['URL_ARRAY']['catid'] = $catid;  
改成:
  1. $GLOBALS['URL_ARRAY']['categorydir'] = $parentdir;  
  2. $GLOBALS['URL_ARRAY']['catdir'] = $catdir;  
  3. $GLOBALS['URL_ARRAY']['catid'] = $catid;  

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、分页问题处理 \phpcms\libs\functions\global.func.php
  1. /**  
  2.  * 返回分页路径  
  3.  *  
  4.  * @param $urlrule 分页规则  
  5.  * @param $page 当前页  
  6.  * @param $array 需要传递的数组,用于增加额外的方法  
  7.  * @return 完整的URL路径  
  8.  */  
  9.    
  10. function pageurl($urlrule, $page, $array = array()) {  
  11.     if(strpos($urlrule, '~')) {  
  12.         $urlrules = explode('~', $urlrule);  
  13.         $urlrule = $page < 2 ? $urlrules[0] : $urlrules[1];  
  14.     }  
  15.     $findme = array('{$page}');  
  16.     $replaceme = array($page);  
  17.     if (is_array($array)) foreach ($array as $k=>$v) {  
  18.         $findme[] = '{$'.$k.'}';  
  19.         $replaceme[] = $v;  
  20.    
  21.     }  
  22.    
  23.     $url = str_replace($findme, $replaceme, $urlrule);  
  24.     $url = str_replace(array('http://','//','~'), array('~','/','http://'), $url);  
  25.     if (!strstr($url,siteurl(get_siteid()))){  
  26.                 $url = siteurl(get_siteid()) . '/' . $url;  
  27.         }  
  28.     return $url;    
  29.    
  30. }  

(4)后台增加伪静态url规则

  1. URL规则栏目页:{$categorydir}{$catdir}/|{$categorydir}{$catdir}/index_{$page}.html 
  2. URL规则内容页: {$categorydir}{$catdir}/{$id}.html|{$categorydir}{$catdir}/{$id}_{$page}.html 
(5)增加伪静态规则
.htaccess为例:
  1. RewriteEngine on  
  2. #静态文件以及API目录不需要伪静态  
  3. RewriteRule ^(statics|api|uploadfile)(.*) – [L]  
  4. #内容页  
  5. RewriteRule ^([0-9A-Za-z_/]*)/([0-9]+)\.html index.php?m=content&c=index&a=show&dir=$1&id=$2  
  6. RewriteRule ^([0-9A-Za-z_/]*)/([0-9]+)_([0-9]+)\.html index.php?m=content&c=index&a=show&dir=$1&id=$2&page=$3  
  7. #栏目页  
  8. RewriteRule ^([0-9A-Za-z_/]*)/index_([1-9][0-9]*)\.html index.php?m=content&c=index&a=lists&dir=$1&page=$2  
  9. RewriteRule ^([0-9A-Za-z_/]*)/ index.php?m=content&c=index&a=lists&dir=$1  
¥ 打赏
×
如果您觉得文章帮助了您就打赏一下吧
非常感谢你的打赏,我们将继续分享更多优质内容,让我们一起创建更加美好的网络世界!

支付宝扫一扫打赏

微信扫一扫打赏

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

文章点评

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

添加微信好友

添加微信好友

微信小程序

百度小程序