织梦园模板网提供云优cms模板,pbootcms模板,Wordpress主题模板等各类企业新闻资讯网站模板下载服务。织梦园网站模板交流群
用户名:
密码:
注册
注册后享受折扣价

dedecms5.7 生成百度地图sitemap和谷歌地图sitemap教程

织梦园模板 / 2020-05-11 / 收藏
今天就研究了下怎么用织梦dedecms生成正确的sitemap文件 。
织梦dedecms生成百度地图 。
好了 直接看步骤吧 。
1.dedecms 生成里面有一个生成地图,原来这个生成的是html,不是我们想要的,而且只生成栏目的,没文章,但是这个界面我们可以方便操作,所以就在这上面来进行修改 。
2.在 /templets/plus 目录下 找到两个文件sitemap.htm 和 rssmap.htm,前者我们当中是百度的sitemap 后者我们当中谷歌的sitemap  。
3. 
修改sitemap.htm :把原来的代码全部删除 然后用下面的代码 。
<?xml version="1.0" encoding="{dede:global.cfg_soft_lang /}"?>
 <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> 
 <url> 
 <loc>{dede:global.cfg_basehost/}</loc> 
 <changefreq>always</changefreq> 
 <priority>1.0</priority> 
 </url> 
{dede:arclist row='10000' orderby='pubdate'}
<url> 
 <loc>[field:global.cfg_basehost/][field:arcurl/]</loc> 
 <lastmod>[field:pubdate function="GetDateMK(@me)"/]</lastmod> 
</url> 
{/dede:arclist} 
{dede:channelartlist row='50'}
 <url>
 <loc>{dede:global.cfg_basehost/}{dede:field name='typeurl'/}</loc>
 <lastmod>{dede:php}echo date('Y-m-d');{/dede:php}</lastmod>
 </url>
 {dede:channel type='son' row='8'}
 <url>
 <loc>[field:global.cfg_basehost/][field:typelink/]</loc>
 <lastmod>[field:id runphp="yes"]@me=date('Y-m-d');[/field:id]</lastmod>
 </url>
 {/dede:channel}
 {/dede:channelartlist}
</urlset>
 
修改rssmap.htm:把原来的代码全部删除 然后用下面的代码
 
 
<?xml version='1.0' encoding='UTF-8'?>
    <urlset xmlns='http://www.google.com/schemas/sitemap/0.84'>
      {dede:arclist typeid='0' } 
       <url><loc>[field:global.cfg_basehost/][field:arcurl/]</loc><lastmod>[field:pubdate function="MyDate('Y-m-d',@me)"/]</lastmod><changefreq>daily</changefreq><priority>1.0</priority></url>
      {/dede:arclist}
      {dede:channelartlist row=50}
        <url><loc>{dede:global.cfg_basehost/}{dede:field name='typeurl'/}</loc><lastmod>{dede:php}echo date('Y-m-d');{/dede:php}</lastmod><changefreq>daily</changefreq><priority>1.0</priority></url>
           {dede:channel type='son' row='8'}
        <url><loc>[field:global.cfg_basehost/][field:typelink/]</loc><lastmod>[field:id runphp="yes"]@me=date('Y-m-d');[/field:id]</lastmod><changefreq>daily</changefreq><priority>1.0</priority></url>
{/dede:channel}
{/dede:channelartlist}
</urlset>
大家也可以自行修改条数
4.重点 
之前我就是这个地方有问题,一直生成不了数据,后来改了一些方法调用才OK
找到dede后台目录 找到 makehtml_map.php  修改
在上面引用文件的时候 加一句 :require_once DEDEINC.”/arc.partview.class.php”;
搜索 if($dopost==”site”)
然后把这个判断里面的代码替换掉:
if($dopost==”site”)
{
$murl = $cfg_cmspath.”/sitemap.xml”;
$tmpfile = $cfg_basedir.$cfg_templets_dir.”/plus/sitemap.htm”;
}else
{
$murl = $cfg_cmspath.”/rssmap.xml”;
$tmpfile = $cfg_basedir.$cfg_templets_dir.”/plus/rssmap.htm”;
}
(原因: 1.html改为xml 不用多说 格式问题      2.把data去掉了,因为sitemap这样的文件放到根目录效果更好 )
//$dtp = new DedeTagParse();
//$dtp->LoadTemplet($tmpfile);
//$dtp->SaveTo($cfg_basedir.$murl);
把这3句话注释掉
在上面的判断下面加入
$pv = new PartView();
$pv->SetTemplet($tmpfile); //在这里修改你的谷歌地图模板路径,相对于模板目录
$pv->SaveToHtml($cfg_basedir.$murl); //生成文件名,保存在根目录

相关织梦技巧

收缩