织梦首页调用随机文章并定时自动更新

    织梦首页调用随机文章并定时自动更新,在plus目录下新建一个random.php的php文件写入以下代码:

    <?

    $updatetime = 2000;//自动更新时间,单位为秒,可以自行更改。

    $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 = "default/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/random.php" type="text/javascript"></script>

    最后重新生成首页,做完这些就完成了调用随机文章并定时自动更新