DedeCMS教程定時生成主頁HTML的實現方法_DedeCms教程

      編輯Tag賺U幣
      使用dedecms(織夢)更加便捷有效,今天給大家發個dedecms技巧教程。
      通過教程方法可以實現 定時生成主頁HTML!
      自動更新主要應用于,采集站,直接可以自動處理。

      織夢DedeCMS自動生成首頁html 

      1、需要在首頁調用隨機文章,這樣每次自動更新才會有更新的效果,隨機文章調用標簽如下:
       {dede:arclist sort='rand' titlelen=48 row=16}
      <li><a href="[field:arcurl/]" title="[field:title/]" target="_blank">[field:title/]</a></li>
      {/dede:arclist}
      2、寫一個觸發定時自動更新的php文件:
      復制下面代碼,粘貼到一個新文件中,命名為:autoindex.php,上傳到ftp的plus文件夾中,錯了位置不會生效:
      <?php
      function sp_input( $text )
      {
      $text = trim( $text );
      $text = htmlspecialchars( $text );
      if (!get_magic_quotes_gpc())
      return addslashes( $text );
      else
      return $text;
      }
      $autotime = 10800;//自動更新時間,單位為秒
      $fpath = "../data/last_time.inc";//記錄更新時間文件,如果不能達到目的,請檢查是否有讀取權限。
      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”;//這里是首頁模板位置,當前是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 );
      }
      ?>

      3、在首頁的模版代碼head標簽中引入觸發文件代碼:
       <script src="/plus/autoindex.php" type="text/javascript"></script>

      然后手動更新一下首頁,接下來在設置的時間過了以后如果有用戶訪問首頁就會觸發自動更新文件,首頁就會自動更新一次。
       

      查看更多 DedeCms教程  織夢模板  織夢DedeCms視頻教程  織夢dedecms專題

      來源:未知//所屬分類:DedeCms教程/更新時間:2020-03-24
      相關DedeCms教程