1G全能免费空间 | 2GB免费全能空间 | 1G免费全能空间 | 免费试用云服务器 | 国内1G免费空间 | 免费空间 | 免费空间申请
您的位置:首页 > 免费教程

织梦dedecms定时自动更新首页的方法

作者:免费空间 发布时间:2019-01-14 [手机版]

织梦dedecms定时自动更新首页的方法如下:

1、在 根目录/plus 目录下新建一个php文件,命名为:autoindex.php

2、将以下代码复制到 autoindex.php 文件

01<?php
02 
03function sp_input( $text )
04 
05{
06 
07$text = trim( $text );
08 
09$text = htmlspecialchars( $text );
10 
11if (!get_magic_quotes_gpc())
12 
13return addslashes( $text );
14 
15else
16 
17return $text;
18 
19}
20 
21$autotime = 3600;//自动更新时间,单位为秒,这里我设为一小时,大家可以自行更改。
22 
23$fpath = "../data/last_time.inc";//记录更新时间文件,如果不能达到目的,请检查是否有读取权限。
24 
25include( $fpath );
26 
27if( empty($last_time))
28 
29$last_time = 0;
30 
31if( sp_input($_GET['renew'])=="now")
32 
33$last_time = 0;
34 
35if((time()-$last_time)>=$autotime )
36 
37{
38 
39define('DEDEADMIN', ereg_replace("[/\\]{1,}",'/',dirname(__FILE__) ) );
40 
41require_once(DEDEADMIN."/../include/common.inc.php");
42 
43require_once(DEDEINC."/arc.partview.class.php");
44 
45/*
46 
47$row = $dsql->GetOne("Select * From dede_homepageset");
48 
49$dsql->Close();
50 
51$templet=$row['templet'];
52 
53$position=$row['position'];
54 
55*/
56 
57$templet = “tnbjh/index.htm”;//这里是首页模板位置,当前是dede默认首面位置。
58 
59$position = "../index.html";
60 
61$homeFile = dirname(__FILE__)."/".$position;
62 
63$homeFile = str_replace("\\", "/", $homeFile );
64 
65$homeFile = str_replace( "//", "/", $homeFile );
66 
67$pv = new PartView();
68 
69$pv ->SetTemplet( $cfg_basedir.$cfg_templets_dir."/".$templet );
70 
71$pv -> SaveToHtml( $homeFile );
72 
73$pv -> Close();
74 
75$file = fopen( $fpath, "w");
76 
77fwrite( $file, "<?php\n");
78 
79fwrite( $file,"\$last_time=".time().";\n");
80 
81fwrite( $file, '?>' );
82 
83fclose( $file );
84 
85}
86 
87?>

3、在首页模板的<head></head>标签中加入如下代码

<script src="/plus/autoindex.php" language="javascript"></script>

以上就是本文章的内容,希望对大家有所帮助


相关推荐
免费空间声明:
(一) 由于各方面情况的调整与变化,本网所提供的考试信息仅供参考,敬请以权威部门公布的正式信息为准。
(二) 本网注明来源为其他媒体的稿件均为转载稿,免费转载出于非商业性学习目的,版权归原作者所有。如有内容、版权等问题请在30日内与本网联系。联系方式:邮件 jiansou123@126.com
最近更新
-->
网站地图 | XML地图 | 手机版
版权所有 © 2005-2022 www.128sj.com 免费空间 All Rights Reserved
本网站所有信息全是来源于互联网,如有侵权请来电咨询! 粤ICP备16040413号-1