phpcms v9網站如何生成地圖sitemap靜態頁面

最新福利:領取阿里雲1000通用代金券

phpcms v9網站如何生成地圖sitemap靜態頁面
第一步:
後臺添加一個菜單,如下填寫:

phpcms v9網站如何生成地圖sitemap靜態頁面
 

本帖隱藏的內容

第二步,將以下代碼保存爲 sitemap.php 文件放到 phpcmsmodulesadminsitemap.php :

<?php
defined('IN_PHPCMS') or exit('No permission resources.');
pc_base::load_app_class('admin','admin',0);
pc_base::load_sys_class('form', '', 0);
class sitemap extends admin {
function __construct() {
parent::__construct();
//欄目級別選項
$this->siteid = $this->get_siteid();
$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('當前站點網站地址成功!');
}

}
?>
第三步,將以下代碼保存爲 sitemap.html 文件,放到 phpcmstemplatesdefaultcontentsitemap.html :


{template 'content','header'}
<div id="main_full">
<div id="position"><a href="">首頁</a>網站地圖</div>
<div id="sitemap">

{loop $CATEGORYS $childid $c}
{php $arrcats = explode(',',$c[arrparentid]);}
{if in_array($catid,$arrcats)}<!-- 判斷只有子欄目的 -->
{if $c['ismenu']==1}<!-- 判斷欄目是否設置顯示 -->
<a href="{$c[url]}">{$c[catname]}</a>
{/if}
{/if}
{/loop}
</p>
{/if}
<!-- 判斷沒有子欄目且設置顯示的 -->
{if $cat['child']==0 and $cat['parentid']==0 and $cat['ismenu']==1}
<h3>{$child}<a href="{$cat[url]}">{$cat[catname]}</a>{$parentid}</h3>{/if}
{/loop} </div>
</div>
{template 'content','footer'}

最新福利:領取阿里雲1000通用代金券

發佈了28 篇原創文章 · 獲贊 25 · 訪問量 6萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章