建站帮助

诚信合作, 高质专业!

Phpcms V9设置网站地图Sitemap静态地图的两种方法

2015-05-27 20:20:00 浏览 我要评论

熟悉Phpcms v9的朋友想必知道,Phpcms v9默认只有Sitemap.xml的生成,而没有网站地图Sitemap.html静态地图,今天CMSYOU在这里与大家分享Phpcms V9设置网站地图Sitemap静态地图的两种方法。

先来百科下网站sitemap静态地图:

Sitemap 可方便网站管理员通知搜索引擎他们网站上有哪些可供抓取的网页。最简单的 Sitemap 形式,就是XML 文件,在其中列出网站中的网址以及关于每个网址的其他元数据(上次更新的时间、更改的频率以及相对于网站上其他网址的重要程度为何等),以便搜索引擎可以更加智能地抓取网站。

可见,Sitemap静态地图有利于蜘蛛的抓取,对于seo优化来说相当重要,而今天讲解的并非用于优化的xml的sitemap,而是方便用户查阅浏览的Sitemap.html静态地图。

Phpcms V9设置网站地图Sitemap静态地图方法一:通过新建sitemap模型生成sitemap.html。

具体方法:

1、新建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('当前站点网站地址成功!'); 
?> 

2、新建模版文件sitemap.html,放置位置:phpcms/templates/default/content/sitemap.html(其中黄色部分default是你的模板文件夹目录),内容为:

{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 $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'}

我要收藏
点个赞吧

相关阅读

本月热门

精选推荐

在线客服

扫一扫,关注我们

扫一扫,关注我们