顺利解决Dedecms系统下生成Google Sitemap问题
今天在使用Google管理员工具的时候,对手下一个dedecms网站提交sitemap,才发现dedecms还没有sitemap.xml文件,于是在百度了一番,发现了个好方法,原文的解决方案是:
1.在模版目录新建一个index.xml文件,内容如下:
<?xml version=”1.0″ encoding=”UTF-8″?>
<urlset xmlns=”http://www.google.com/schemas/sitemap/0.84″> <url>
<loc>http://www.iiseo.com</loc> </url> {dede:arclist row=”9999″ col=1 titlelen=”200″ orderby=”pubdate”}
<url>
<loc>http://www.iiseo.com[field:arcurl /]</loc>
</url>{/dede:arclist} .
</urlset>
//请将其中网址改成您自己的. Row后面的数字请根据您自己的内容来定.例如您有1W文章可以写10000或者更大数字.
2.在后台点更新首页.模版选index.xml.
生成位置写站点根目录名称随便.如(sitemap.xml)
然后点生成就可以了.
后来发现这样做的话会自动将主页设置为sitemap.xml,所以就得重新生成index.html文件,于是这样每次更新就显得很麻烦,老七修改了下后台,实现了后台字节更新sitemap的功能。简单方法介绍如下:
1、添加导航。打开/dede/inc/inc_menu.php文件,找到
<m:item name=’更新主页HTML’ link=’makehtml_homepage.php’ rank=’sys_MakeHtml’ target=’main’ />
复制一条,并修改为
<m:item name=’更新Sitemap’ link=’makehtml_sitemap.php’ rank=’sys_MakeHtml’ target=’main’ />
2、制作dede/makehtml_sitemap.php文件,直接拷贝一个dede/makehtml_homepage.php文件,找到
$pv->SetTemplet($cfg_basedir.$cfg_templets_dir.”/”.$templet);
$pv->SaveToHtml($homeFile);
这段代码,将其删除,然后另存为makehtml_sitemap.php,上传至dede/即可。
3、制作后台更新模板文件dede/templets/makehtml_sitemap.htm,直接拷贝一个dede/templets/makehtml_sitemap.htm文件,找到
<input name=”templet” type=”text” id=”templet” style=”width:300″ value=”<?php echo $row['templet']?>”>
和
<td height=”20″ valign=”top” bgcolor=”#FFFFFF”><input name=”position” type=”text” id=”position” value=”<?php echo $row['position']?>” size=”30″>
分别修改为:
<input name=”templet” type=”text” id=”templet” style=”width:300″ value=”default/sitemap.xml”>
<td height=”20″ valign=”top” bgcolor=”#FFFFFF”><input name=”position” type=”text” id=”position” value=”../sitemap.xml” size=”30″>
然后另存为makehtml_sitemap.htm,上传至dede/templets/;
4、制作sitemap模板文件templets/sitemap.xml,将
<?xml version=”1.0″ encoding=”UTF-8″?>
<urlset xmlns=”http://www.google.com/schemas/sitemap/0.84″> <url>
<loc>http://www.cehuashu.net.cn</loc> </url> {dede:arclist row=”9999″ col=1 titlelen=”200″ orderby=”pubdate”}
<url>
<loc>http://www.cehuashu.net.cn[field:arcurl /]</loc>
</url>{/dede:arclist} .
</urlset>
用记事本将这段代码存为sitemap.xml,上传至templets/,这样就大功告成了。
PS:若有谁有更好的办法,不妨提出来大家分享。现提供相关文件的下载:http://www.0cai.net/wp/file/dedecms-sitemap.rar
特表强调下,本人用的gb2312,使用utf8的请注意编码问题。