今天我們介紹下織夢(mèng)(dedecms)系統(tǒng)完整自動(dòng)更新主頁(yè)方法,現(xiàn)在分享給大家學(xué)習(xí)參考,跟著小編一起學(xué)習(xí)把。之前我們也介紹了dedecms讓編輯文檔也能自動(dòng)更新主頁(yè)和列表頁(yè),更多的織夢(mèng)dedecms教程。
織夢(mèng)自動(dòng)更新主頁(yè)適用場(chǎng)景:
1:采集站點(diǎn)可以適用此功能,省去了人工生成,節(jié)省時(shí)間。
2:懶人專用,逼格更上一個(gè)層次。
織夢(mèng)DedeCMS自動(dòng)生成首頁(yè)html,具體方法如下:
第一步、需要在首頁(yè)調(diào)用隨機(jī)文章,這樣每次自動(dòng)更新才會(huì)有更新的效果,隨機(jī)文章調(diào)用標(biāo)簽如下:
{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)用出的文章在每次自動(dòng)生成首頁(yè)的時(shí)候都會(huì)變化。
第二步、寫(xiě)一個(gè)觸發(fā)定時(shí)自動(dòng)更新的php文件:
復(fù)制下面代碼,粘貼到一個(gè)新文件中,命名為:autoindex.php,上傳到ftp的plus文件夾中,看清楚一點(diǎn)是plus文件夾中,錯(cuò)了位置不會(huì)生效:
<?php function sp_input( $text ) { $text = trim( $text ); $text = htmlspecialchars( $text ); if (!get_magic_quotes_gpc()) return addslashes( $text ); else return $text; } $autotime = 10800;//自動(dòng)更新時(shí)間,單位為秒 $fpath = "../data/last_time.inc";//記錄更新時(shí)間文件,如果不能達(dá)到目的,請(qǐng)檢查是否有讀取權(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”;//這里是首頁(yè)模板位置,當(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 ); } ?> |
第三步、在首頁(yè)的模版代碼head標(biāo)簽中引入觸發(fā)文件代碼:
<script src="/plus/autoindex.php" type="text/javascript"></script> |
然后手動(dòng)更新一下首頁(yè),接下來(lái)在設(shè)置的時(shí)間過(guò)了以后如果有用戶訪問(wèn)首頁(yè)就會(huì)觸發(fā)自動(dòng)更新文件,首頁(yè)就會(huì)自動(dòng)更新一次。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持我們。