日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > php >内容正文

php

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

發(fā)布時(shí)間:2025/4/16 php 42 豆豆
生活随笔 收集整理的這篇文章主要介紹了 php v9 分页静态,PHPCMS V9自定义栏目伪静态实现方法(列表页/分页/内容页) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

phpcmsV9 欄目偽靜態(tài)的修改方法(支持自定義目錄名),官方程序默認(rèn)偽靜態(tài)是不支持自定義欄目名的,所以今天就做了以下修改,讓其支持!

一、編寫.htaccess中的urlrewrite規(guī)則

首先看urlrewrite的規(guī)則,這個(gè)是Apache下的,其它環(huán)境下的規(guī)則自己轉(zhuǎn)換下

RewriteEngine on

#靜態(tài)文件以及API目錄不需要偽靜態(tài)

RewriteRule ^(statics|api|uploadfile)(.*) - [L]

#內(nèi)容頁(yè)

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

#欄目頁(yè)

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

二、更新phpcms\modules\content目錄下的index.php

1、在 //首頁(yè)? 前面新增如下函數(shù)

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'];

}

2、分別在`lists()`和`show()`方法中,將獲取`catid`的語(yǔ)句修改

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

替換

//$catid = intval($_GET['catid']);

if(isset ($_GET['catid'])){

$catid = intval($_GET['catid']);

}else{

$catid=$this->_getCategoryId($_GET['dir']);

}

3、找到 //URL規(guī)則下面的

$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;

三、然后在phpcms后臺(tái),添加兩條自定義的URL規(guī)則

URL規(guī)則欄目頁(yè):{$categorydir}{$catdir}/|{$categorydir}{$catdir}/index_{$page}.html

URL規(guī)則內(nèi)容頁(yè): {$categorydir}{$catdir}/{$id}.html|{$categorydir}{$catdir}/{$id}_{$page}.html

然后再更新欄目緩存、批量更新URL就可以看到效果了

四、修改phpcms\modules\content\classes目錄中的url.class.php 找到if (!$setting['ishtml']) { //如果不生成靜態(tài)

將下面的:

$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."
";

if (strpos($urls, '\\')!==false) {

$urls = APP_PATH.str_replace('\\', '/', $urls);

}

$url = $domain_dir.$urls;

更新欄目緩存就OK了。

五、分頁(yè)問(wèn)題處理

找到文件 \phpcms\libs\functions\global.func.php

/**

* 返回分頁(yè)路徑

*

* @param $urlrule 分頁(yè)規(guī)則

* @param $page 當(dāng)前頁(yè)

* @param $array 需要傳遞的數(shù)組,用于增加額外的方法

* @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;

}

總結(jié)

以上是生活随笔為你收集整理的php v9 分页静态,PHPCMS V9自定义栏目伪静态实现方法(列表页/分页/内容页)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。