phpcms v9生成网站地图静态html

第一步:

后台添加一个菜单,如下填写:

\
第二步,将以下代码保存为 sitemap.php 文件放到 \phpcms\modules\admin\sitemap.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 文件,放到 \phpcms\templates\default\content\sitemap.html  :

{template ‘content’,’header’}<!– 地图Main  Start–>
<div id=”main_full”>
<div id=”position”><a href=””>首页</a> > 网站地图</div>
<div id=”sitemap”>
<ul>
<?php
$c=0;
for($i=0;$i<=count($CATEGORYS);$i++){
$chid=$CATEGORYS[$i][arrchilid];
$pid=$CATEGORYS[$i][parentid];
$cid=$CATEGORYS[$i][catid];
$cname=$CATEGORYS[$i][catname];

if($pid==0){
?>
{if $cid!=$pid}
<li><a href=”#” target=”_blank”>{php echo $cname;}</a></li>
{pc:content action=”category”  catid=”$cid” num=”7″}
{loop $data $r}
<dd><a href=”{$r[url]}” target=”_blank”>{$r[catname]}</a></dd>
{/loop}
{/pc}
{/if}

<?php

}

}
?>

</ul>
</div>
</div>

{template ‘content’,’footer’}

Published by 小车

网站技术工人