很多用戶的企業站更新頻率不高,有的甚至大幾個月到幾年都不會更新,這個其實對于SEO來說是不理想的,所以我們就要像辦法讓我們的網站首頁“自動更新”起來。因為我們很多站點都已經靜態化了,所以不能使用php來直接實現定時自動更新,就需要記住JS來實現。所以我們首先先在我們的模板首頁書寫調用一些隨機顯示的文章產品標簽,方便我們生成的時候模擬新頁面的效果,然后再在plus目錄下新建一個名為autoupdate.php的php文件,代碼如何下:
<?$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>
然后再重新生成一下首頁,就能實現自動定時更新網站首頁了。有需求的朋友去嘗試看看吧。
新聞熱點
疑難解答