
| 歡迎訪問全國企業網站設計NO.1網站開發商平臺 | 付款方式 |
POST TIME:2020-10-09
<?
$updatetime = 1800;//自動更新時間,單位為秒,這里我設為一小時,大家可以自行更改。
$fpath = "../data/update_time.inc";//記錄更新時間文件,如果不能達到目的,請檢查是否有讀取權限。
include( $fpath );
if(empty($last_time)){
$last_time = 0;
}
if((time()-$last_time)>=$updatetime )
{
define('DEDEADMIN', ereg_replace("[/\\]{1,}",'/',dirname(__FILE__) ) );
require_once(DEDEADMIN."/../include/common.inc.php");
require_once(DEDEINC."/arc.partview.class.php");
$templet = "xunmzy/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 );
}
?>
|
然后在首頁插入一下js:
<script src="/plus/autoupdate.php" type="text/javascript"></script> |
最后重新生成首頁,做完這些就完成了調用隨機文章并定時自動更新