這篇文章主要介紹dedecms如何實現定時生成站點地圖,定時生成首頁也可以用這個思路,這里用到了dedecms后臺的計劃任務功能來完成。
下面是具體操作步驟:
第一步、首先在模板目錄放一個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=2000 orderby=pubdate}
<url>
<loc>[field:arcurl/]</loc>
<lastmod>[field:pubdate function=strftime('%Y-%m-%d',@me)/]</lastmod>
<changefreq>monthly</changefreq>
</url>
{/dede:arclist}
</urlset>
第二步、寫一個計劃任務文件命名為generate_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.'/2012/sitemap.xml');
$html = $lv->PartView->GetResult();
file_put_contents('../../sitemap.xml',$html);
?>
第三步、在后臺添加計劃任務,系統——計劃任務管理——增加新任務:
任務名稱:定時生成網站地圖;
運行程序:generate_sitemap.php;
執行時間自己設置;
其他默認即可。
第四步、在模板目錄的foot.hml文件或其他公共include文件body結束之前加上觸發代碼即可。
在計劃任務規定的時間內瀏覽一下網頁來觸發計劃任務文件執行。如果上次運行時間的時間正常就證明定時任務執行成功。
評論(0人參與,0條評論)
發布評論
最新評論