织梦dedecms自动更新网站地图的教程

2019-10-24,,

第一步、首先在模板目录放一个sitemap.xml的模板文件,文件的内容如下:

 

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>/</loc>
<lastmod>{dede:arclist row=1 titlelen=24 orderby=pubdate}
[field:pubdate function=strftime('%Y-%m-%d',@me)/]
{/dede:arclist}</lastmod>
<changefreq>daily</changefreq>
<priority>1.0</priority>
</url>
{dede:channel row='10' type='top'}
<url>
<loc>[field:typelink /]</loc>
<changefreq>daily</changefreq>
<priority>0.8</priority>
</url>
{/dede:channel}
{dede:arclist row=1000 orderby=pubdate}
<url>
<loc>[field:arcurl/]</loc>
<lastmod>[field:pubdate function=strftime('%Y-%m-%d',@me)/]</lastmod>
<changefreq>monthly</changefreq>
</url>
{/dede:arclist}
</urlset>

 

第二步、手动写一个计划任务执行文件,将该文件命名为lol9_sitemap.php,放在/plus/task目录里,文件的内容如下:

<?php
//定时生成网站地图
require_once(dirname(__FILE__).'/../../include/common.inc.php');
include(DEDEINC."/arc.listview.class.php");
$lv = new ListView();
 
//解析模板到字符串
$lv->PartView = new PartView($lv->TypeID,false);
$lv->PartView->SetTypeLink($lv->TypeLink);
$lv->PartView->SetTemplet(DEDETEMPLATE.'/dede58.com/sitemap.xml');
$html = $lv->PartView->GetResult();
file_put_contents('../../sitemap.xml',$html);
?>

 

/dede58.com/sitemap.xml 是模板文件所目录名称,更换成自己的模板目录即可。

 

第三步、在织梦后台添加计划任务,系统——计划任务管理——增加新任务:

任务名称:定时生成网站地图

运行程序:lol9_sitemap.php

执行时间自己根据需要进行适当的设置

其它选项默认即可。

 

第四步、在模板目录的foot.hml文件或其他公共模板include文件的body标签结束之前加上代码后生成全站即可。

 

添加完成后网站用户在计划任务规定的时间内浏览一下网页就可以触发计划任务文件的执行,就可以自动生成一次sitemap.xml,如果上次运行时间的时间正常就证明定时任务执行成功了。

《织梦dedecms自动更新网站地图的教程.doc》

下载本文的Word格式文档,以方便收藏与打印。