Phpcms V9添加網站地圖Sitemap靜態地圖方法(一)

1、新增函數文件sitemap.php,並上傳到網站程序目錄: phpcms/modules/admin/文件夾下。php

文件內容:html

defined('IN_PHPCMS') or exit('No permission resources.'); 緩存

pc_base::load_app_class('admin','admin',0); app

pc_base::load_sys_class('form', '', 0); dom

class sitemap extends admin { 函數

function __construct() { 網站

parent::__construct(); this

//欄目級別選項 google

$this->siteid = $this->get_siteid(); spa

$this->categorys = getcache('category_content_'.$this->siteid,'commons'); 

/** 

* Enter google sitemap, 百度新聞協議 

*/ 

function init() { 

$hits_db = pc_base::load_model('hits_model'); 

$CATEGORYS = $this->categorys; 

//讀站點緩存 

$siteid = $this->siteid; 

$sitecache = getcache('sitelist','commons'); 

//根據當前站點,取得文件存放路徑 

$systemconfig = pc_base::load_config('system'); 

$html_root = substr($systemconfig['html_root'], 1); 

//判斷當前站點目錄,是PHPCMS則把文件寫到根目錄下, 不是則寫到分站目錄下.(分站目錄用由靜態文件路經html_root和分站目錄dirname組成) 

if($siteid==1){ 

$dir = PHPCMS_PATH; 

}else { 

$dir = PHPCMS_PATH.$html_root.DIRECTORY_SEPARATOR.$sitecache[$siteid]['dirname'].DIRECTORY_SEPARATOR; 

//模型緩存 

$modelcache = getcache('model','commons'); 

if(!defined('HTML')) define('HTML',1); 

//獲取當前站點域名,下面URL時會用到. 

$this_domain = substr($sitecache[$siteid]['domain'], 0,strlen($sitecache[$siteid]['domain'])-1); 

ob_start(); 

$file = $dir.'sitemap.html'; 

include template('content', 'sitemap'); 

$data = ob_get_contents(); 

ob_clean(); 

if(!is_dir($dir)) { 

mkdir($dir, 0777,1); 

file_put_contents($file, $data); 

@chmod($file,0777); 

showmessage('當前站點網站地址成功!'); 

?> 

2、新增模板文件sitemap.html ,並上傳到程序目錄:phpcms/templates/cmsyou/content/文件夾下。

相關文章
相關標籤/搜索