织梦cms生成首页html的php文件,织梦DedeCMS定时自动生成首页HTML的实现方法
只需要制作一個(gè)文件然后在首頁模板添加一句代碼就可以實(shí)現(xiàn)讓織夢DedeCMS自動(dòng)生成首頁html,具體方法如下:
第一步、需要在首頁調(diào)用隨機(jī)文章,這樣每次自動(dòng)更新才會(huì)有更新的效果,隨機(jī)文章調(diào)用標(biāo)簽如下:
{dede:arclist sort='rand' titlelen=48 row=16}
[field:title/]{/dede:arclist}
這段代碼調(diào)用出的文章在每次自動(dòng)生成首頁的時(shí)候都會(huì)變化。
第二步、寫一個(gè)觸發(fā)定時(shí)自動(dòng)更新的php文件:
復(fù)制下面代碼,粘貼到一個(gè)新文件中,命名為:autoindex.php,上傳到ftp的plus文件夾中,看清楚一點(diǎn)是plus文件夾中,錯(cuò)了位置不會(huì)生效:
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á)到目的,請檢查是否有讀取權(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”;//這里是首頁模板位置,當(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)簽中引入觸發(fā)文件代碼:
然后手動(dòng)更新一下首頁,接下來在設(shè)置的時(shí)間過了以后如果有用戶訪問首頁就會(huì)觸發(fā)自動(dòng)更新文件,首頁就會(huì)自動(dòng)更新一次。
免責(zé)聲明:本站所有文章和圖片均來自用戶分享和網(wǎng)絡(luò)收集,文章和圖片版權(quán)歸原作者及原出處所有,僅供學(xué)習(xí)與參考,請勿用于商業(yè)用途,如果損害了您的權(quán)利,請聯(lián)系網(wǎng)站客服處理。
本站vip會(huì)員 請加入織夢58 VIP②群 PS:加入時(shí)備注用戶名或昵稱
普通注冊會(huì)員或訪客 請加入織夢58 技術(shù)交流②群
總結(jié)
以上是生活随笔為你收集整理的织梦cms生成首页html的php文件,织梦DedeCMS定时自动生成首页HTML的实现方法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python 示例_带有示例的Pytho
- 下一篇: ctype函数_PHP ctype_cn