• 方法如下
我們知道織夢多數(shù)情況下是生成靜態(tài)的html文件的,這樣一方面可以減少服務(wù)器的負(fù)荷,另一方面也是為了優(yōu)化,但是織夢本身靜態(tài)要手動更新生成,不是自動的,今天我們就來說一下怎樣實(shí)現(xiàn)自動更新.
  • 調(diào)用隨機(jī)文章
{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,把下面代碼復(fù)制進(jìn)去,上傳到ftp的plus文件夾中。
<?php
function sp_input( $text )
{
$text = trim( $text );
$text = htmlspecialchars( $text );
if (!get_magic_quotes_gpc())
return addslashes( $text );
else
return $text;
}
$autotime = 3600;//自動更新時間,單位為秒,這里我設(shè)為一小時,大家可以自行更改。
$fpath = "../data/last_time.inc";//記錄更新時間文件,如果不能達(dá)到目的,請檢查是否有讀取權(quán)限。
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";//這里是首頁模板位置,當(dāng)前是dede默認(rèn)首面位置。
$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標(biāo)簽中加入一段代碼:
<script src="/plus/autoindex.php" language="javascript"></script>
然后點(diǎn)擊后臺生成,更新首頁就搞定了。