POST TIME:2020-04-05 22:29
這是一篇介紹dedecms如何定時生成站點地圖的文章,定時生成首頁也是這個思路,這里用到了dedecms后臺的計劃任務功能來完成。
下面就正是開始完成此功能:
<?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>
<?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
執(zhí)行時間自己設置
其他默認即可。
OK! 定時生成網站地圖(sitemap.xml)功能結束,你可以在百度站長平臺里提交這個網站地圖文件,百度robot會更喜歡你的網站!