dedecms首頁怎么調用隨機文章?
本文實例講述了dedecms首頁調用隨機文章及自動更新功能的實現方法。分享給大家供大家參考。具體實現方法如下:
推薦學習:織夢cms
我們知道織夢多數情況下是生成靜態的html文件的,這樣一方面可以減少服務器的負荷,另一方面也是為了優化,但是織夢本身靜態要手動更新生成,不是自動的,今天我們就來說一下怎樣實現自動更新.
(1)調用隨機文章:
織夢給出了隨機文章調用的參數如下:
代碼如下:
{dede:arclist?sort='rand'?titlelen=48?row=16}?
? {/dede:arclist}
(2)置定時自動更新文件:
復制下面代碼,粘貼到一個新文件中,命名為:autoindex.php,上傳到ftp的plus文件夾中,看清楚一點是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;//自動更新時間,單位為秒,這里我設為一小時,大家可以自行更改。 $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 "); fwrite( $file,"$last_time=".time()."; "); fwrite( $file, '?>'?);? fclose(?$file?);? }? ?>
然后我們需要在首頁的模版代碼head標簽中加入一段代碼:
代碼如下:
<script></script>
然后點擊后臺生成,更新首頁,到此就ok了啊.
? 版權聲明
文章版權歸作者所有,未經允許請勿轉載。
THE END
喜歡就支持一下吧
相關推薦