今天我們介紹下織夢(dedecms)系統(tǒng)完整自動更新主頁方法,現(xiàn)在分享給大家學習參考,跟著小編一起學習把。
1:采集站點可以適用此功能,省去了人工生成,節(jié)省時間。
2:懶人專用,逼格更上一個層次。
查看源碼 {dede:arclist sort='rand' titlelen=48 row=16} <li><a href="[field:arcurl/]" title="[field:title/]" target="_blank">[field:title/]</a></li> {/dede:arclist} |
這段代碼調(diào)用出的文章在每次自動生成首頁的時候都會變化。
復制下面代碼,粘貼到一個新文件中,命名為: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 = 10800;//自動更新時間,單位為秒 $fpath = "../data/last_time.inc";//記錄更新時間文件,如果不能達到目的,請檢查是否有讀取權(quán)限。 include( $fpath ); if( empty($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"); /* $row = $dsql->GetOne("Select * From dede_homepageset"); $dsql->Close(); $templet=$row['templet']; $position=$row['position']; */ $templet = “downpk/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 ); } ?> |
查看源碼 <script src="/plus/autoindex.php" type="text/javascript"></script> |
然后手動更新一下首頁,接下來在設(shè)置的時間過了以后如果有用戶訪問首頁就會觸發(fā)自動更新文件,首頁就會自動更新一次。
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持我們。
|
新聞熱點
疑難解答
圖片精選