User-Profile-Image
hankin
  • 5
  • 首页
  • Dedecms
  • Notes
  • php
  • Tools
  • Music
  • 分类
    • Tools
    • php
    • Notes
    • Music
    • Dedecms
  • 页面
  • 友链
      请到[后台->主题设置->友情链接]中设置。
Help?

Please contact us on our email for need any support

Support
  • 首页
  • Dedecms
  • Notes
  • php
  • Tools
  • Music
    首页   ›   Dedecms   ›   正文
Dedecms

Dedecms定时自动生成网站地图sitemap.xml

2014-09-05 15:26:25
4173  0 0

在plus目录下新建一个generatesitemap.php:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
date_default_timezone_set("Asia/Shanghai");
$lasttime=filemtime($_SERVER['DOCUMENT_ROOT']."/sitemap.xml");
$interval=900; //更新时间秒
if((time()-$lasttime)>=$interval)
{
require_once(dirname(__FILE__).'/../include/common.inc.php');
require_once DEDEINC."/arc.partview.class.php";
$content='<!--?xml version="1.0" encoding="UTF-8"?--><!--?xml-stylesheet type="text/xsl" href="/sitemap.xsl"?-->';
$index_lasttime=filemtime($_SERVER['DOCUMENT_ROOT']."/index.html");
$content.="\n";
$content.="http://m.yourdomain.com/\n";
$content.="\n";
$content.="".date('Y-m-d',$index_lasttime)."T".date('H:i:s',$index_lasttime)."+08:00\n";
$content.="always\n";
$content.="1.0\n";
$content.="\n";
$sql="select * from dede_archives where arcrank=0 and ismake=1 order by id desc LIMIT 2200";
$dsql->SetQuery($sql);//将SQL查询语句格式化
$dsql->Execute();//执行SQL操作
while($row = $dsql->GetArray()){
$content.="\n";
$content.="http://m.yourdomain.com".GetOneDocUrl($row['id'])."\n";
$content.="\n";
$content.="".date("Y-m-d",$row['pubdate'])."T".date("H:i:s",$row['pubdate'])."+08:00\n";
$content.="daily\n";
$content.="0.6\n";
$content.="\n";
}
$content.='';
file_put_contents($_SERVER['DOCUMENT_ROOT']."/sitemap.xml",$content);
exit();
}
exit();

 

以上代码$interval=900表示15分钟生成一次,可自行修改。
然后在页面用JS引用:

1
<script src="/plus/generatesitemap.php"></script>

只要有人访问页面就生成了sitemap.xml

评论 (0)

点击这里取消回复。

欢迎您 游客  

Archives
  • 2019年4月
  • 2018年10月
  • 2018年5月
  • 2018年2月
  • 2016年7月
  • 2015年12月
  • 2014年9月
  • 2014年3月
  • 2014年1月
  • 2013年12月
  • 2013年11月
Categories
  • Dedecms
  • Music
  • Notes
  • php
  • Tools
标签
Dedecms Dedecms短信 Dedecms自定义表单 dedecms自定义表单必填字段 dede_fieldshash showmsg sitemap 织梦 网站地图 自定义表单短信
其他操作
  • 登录
  • 条目feed
  • 评论feed
  • WordPress.org
Copyright © 2025
smarty_hankin 主题. Designed by hankin
主页
页面
博主
Alvin 管理员
14 文章 0 评论 57371 浏览
测试
测试