织梦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>
以上就是本文章的内容,希望对大家有所帮助