织梦首页静态化以后,如果不重新生成,它是不变的,即便你在首页随机调用文档也不会自动更新。但是静态页面又不能使用php功能,那又要用到js来引入php文件,才能行得通。下面小编直接告诉大家方法:
在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>
最后重新生成首页,做完这些就完成了调用随机文章并定时自动更新
2、本站永久网址:https://www.yuanmacun.com
3、本网站的文章部分内容可能来源于网络,仅供大家学习与参考,如有侵权,请联系站长进行删除处理。
4、本站一切资源不代表本站立场,并不代表本站赞同其观点和对其真实性负责。
5、本站一律禁止以任何方式发布或转载任何违法的相关信息,访客发现请向站长举报
6、本站资源大多存储在云盘,如发现链接失效,请联系我们我们会第一时间更新。
源码村资源网 » 织梦dedecms首页调用随机文章并定时自动更新