織夢dedecms定時自動更新首頁的方法如下:
1、在 根目錄/plus 目錄下新建一個php文件,命名為:autoindex.php
2、將以下代碼復制到 autoindex.php 文件
<?php
function sp_input( $text )
{
$text = trim( $text );
$text = htmlspecialchars( $text );
if (!get_magic_quotes_gpc())
return addslashes( $text );
else
return $text;
}
$autotime = 3600;//自動更新時間,單位為秒,這里我設為一小時,大家可以自行更改。
$fpath = "../data/last_time.inc";//記錄更新時間文件,如果不能達到目的,請檢查是否有讀取權限。
include( $fpath );
if( empty($last_time))
$last_time = 0;
if( sp_input($_GET['renew'])=="now")
$last_time = 0;
if((time()-$last_time)>=$autotime )
{
define('DEDEADMIN', ereg_replace("[///]{1,}",'/',dirname(__FILE__) ) );
require_once(DEDEADMIN."/../include/common.inc.php");
require_once(DEDEINC."/arc.partview.class.php");
/*
$row = $dsql->GetOne("Select * From dede_homepageset");
$dsql->Close();
$templet=$row['templet'];
$position=$row['position'];
*/
$templet = “tnbjh/index.htm”;//這里是首頁模板位置,當前是dede默認首面位置。
$position = "../index.html";
$homeFile = dirname(__FILE__)."/".$position;
$homeFile = str_replace("//", "/", $homeFile );
$homeFile = str_replace( "//", "/", $homeFile );
$pv = new PartView();
$pv ->SetTemplet( $cfg_basedir.$cfg_templets_dir."/".$templet );
$pv -> SaveToHtml( $homeFile );
$pv -> Close();
$file = fopen( $fpath, "w");
fwrite( $file, "<?php/n");
fwrite( $file,"/$last_time=".time().";/n");
fwrite( $file, '?>' );
fclose( $file );
}
?>
3、在首頁模板的<head></head>標簽中加入如下代碼
<script src="/plus/autoindex.php" language="javascript"></script>
此文由 網站目錄_網站網址收錄與提交入口 編輯,未經允許不得轉載!: