• 全国400电话网上服务平台
    强大号码库资源任选,方便,快捷,快速开通。
    咨询热线:400-1100-266  

    dede首页调用随机文章定时自动更新
    POST TIME:2018-03-15 21:05

    大家做SEO的都知道网站首页的更新频率直接决定了网站的收录速度和一部分站点权重,但是我们不能实时的去更新,在这个科技如此发达的时代如果我们还在采用最原始的办法那一定是个悲剧。没错,就像标题写的一样,自动,没错就是自动,全自动更新首页的文章列表。织梦仿站教程
    第一步调用随机文章:织梦仿站教程
      织梦给出了随机文章调用的参数如下:
    {dede:arclist sort=’rand’ titlelen=48 row=16}
    <li><a href=&quot;[field:arcurl/]&quot; title=&quot;[field:title/]&quot; target=&quot;_blank&quot;>[field:title/]</a></li>
    {/dede:arclist}  这段列表代码可以调用出随机文章,并且在每次刷新动态页面的时候都会变化,但是由于织梦是首页生成静态html的,所以如果不去手动生成还是不会变化,这样就用到了下面的方法。
    第二步设置定时自动更新文件:
      复制下面代码,粘贴到一个新文件中,命名为: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 = 3600;//自动更新时间,单位为秒,这里我设为一小时,大家可以自行更改。
    $fpath = &quot;../data/last_time.inc&quot;;//记录更新时间文件,如果不能达到目的,请检查是否有读取权限。
    include( $fpath );
    if( empty($last_time))
    $last_time = 0;
    if( sp_input($_GET['renew'])==&quot;now&quot;)
    $last_time = 0;
    if((time()-$last_time)>=$autotime )
    {
    define('DEDEADMIN', ereg_replace(&quot;[/]{1,}&quot;,'/',dirname(__FILE__) ) );
    require_once(DEDEADMIN.&quot;/../include/common.inc.php&quot;);
    require_once(DEDEINC.&quot;/arc.partview.class.php&quot;);
    /*
    $row = $dsql->GetOne(&quot;Select * From dede_homepageset&quot;);
    $dsql->Close();
    $templet=$row['templet'];
    $position=$row['position'];
    */
    $templet = “tnbjh/index.htm”;//这里是首页模板位置,当前是dede默认首面位置。
    $position = &quot;../index.html&quot;;
    $homeFile = dirname(__FILE__).&quot;/&quot;.$position;
    $homeFile = str_replace(&quot;&quot;, &quot;/&quot;, $homeFile );
    $homeFile = str_replace( &quot;//&quot;, &quot;/&quot;, $homeFile );
    $pv = new PartView();
    $pv ->SetTemplet( $cfg_basedir.$cfg_templets_dir.&quot;/&quot;.$templet );
    $pv -> SaveToHtml( $homeFile );
    $pv -> Close();
    $file = fopen( $fpath, &quot;w&quot;);
    fwrite( $file, &quot;<?phpn&quot;);
    fwrite( $file,&quot;$last_time=&quot;.time().&quot;;n&quot;);
    fwrite( $file, '?>' );
    fclose( $file );
    }
    ?>  然后我们需要在首页的模版代码head标签中加入一段代码:
    <script src=&quot;/plus/autoindex.php&quot; language=&quot;javascript&quot;></script>  然后点击后台生成,更新首页。
      这样就等待验证结果吧,一点要看清楚上面的注释,时间是以秒为单位的,默认3600秒是一小时,大家可以自行更改。

    
    关于我们 | 付款方式 | 建站知识 | 增值服务 | 网站模板
    Copyright © 2003-2016
    时间:9:00-21:00 (节假日不休)
    版权所有:巨人网络(扬州)科技有限公司
    总部地址:江苏省信息产业基地11号楼四层
    《增值电信业务经营许可证》 苏B2-20120278
    X

    截屏,微信识别二维码

    微信号:veteran88

    (点击微信号复制,添加好友)

     打开微信

    微信号已复制,请打开微信添加咨询详情!