- 方法如下
我們知道織夢多數情況下是生成靜態的html文件的,這樣一方面可以減少服務器的負荷,另一方面也是為了優化,但是織夢本身靜態要手動更新生成,不是自動的,今天我們就來說一下怎樣實現自動更新.
- 調用隨機文章
{dede:arclist sort='rand' titlelen=48 row=16}<li><a href="[field:arcurl/]" title="[field:title/]" target="_blank">[field:title/]</a></li>{/dede:arclist}
- 置定時自動更新文件:
新建一個文件autoindex.php,把下面代碼復制進去,上傳到ftp的plus文件夾中。
<?phpfunction sp_input( $text ){$text = trim( $text );$text = htmlspecialchars( $text );if (!get_magic_quotes_gpc())return addslashes( $text );elsereturn $text;}$autotime = 3600;//自動更新時間,單位為秒,這里我設為一小時,大家可以自行更改。$fpath = "../data/last_time.inc";//記錄更新時間文件,如果不能達到目的,請檢查是否有讀取權限。include( $fpath );if( emptyempty($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");$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 );}?>
在首頁的模版代碼head標簽中加入一段代碼:
<script src="/plus/autoindex.php" language="javascript"></script>
然后點擊后臺生成,更新首頁就搞定了。


