DedeCMS Home Random article calling regular automatic update method

Home update frequency content directly determines your speed and weight of the site site, which requires Home content updates at any time, but sometimes we can not at any time own to manually update, this time, we can give  dedecms set about Home automatic updates, yes, yes that is updated automatically, fully automatic update Home articles list. Specific setting methods automatically update the home operator as follows:

step 1

Add Random article calling on the home page template label inside, everyone here to explain why you want to add tags Random article calls it? Because of the random call tag will call different article content on every refresh, refresh the equivalent of every home has new content displayed, even if the article site can not increase. If the article is just an ordinary call tag, and refreshed home site in case of no increase in content of the article is no new content. Specific call code is as follows:

 
  1. {dede:arclist sort=’rand’ titlelen=48 row=16}
  2. <li><a href="[field:arcurl/]" title="[field:title/]" target="_blank" rel="noopener noreferrer">[field:title/]</a></li>
  3. { / Grandfather : arclist }

Face this code can call a random list of articles, and will change each time you refresh dynamic pages, but because weaving dreams is home to generate static html, so if you do not manually generate or will not change, so use the following Methods.

Step 2

Set up regular automatic update files, copy the code below and paste it into a new file named: autoindex.php, uploaded to the site root directory plus folder.

  1. <?php
  2. function sp_input( $text )
  3. {
  4. $text = trim( $text );
  5. $text = htmlspecialchars( $text );
  6. if (!get_magic_quotes_gpc())
  7. return addslashes( $text );
  8. else
  9. return $text;
  10. }
  11. autotime $ = 3600 ; // automatically update the time, in seconds, where I set one hour, you can change yourself.
  12. fpath $ = "../data/last_time.inc" ; // record update time of the file, if they can not achieve their goals, please check for read access.
  13. include( $fpath );
  14. if( empty($last_time))
  15. $last_time = 0;
  16. if( sp_input($_GET['renew'])=="now")
  17. $last_time = 0;
  18. if((time()-$last_time)>=$autotime )
  19. {
  20. define('DEDEADMIN', ereg_replace("[/\]{1,}",'/',dirname(__FILE__) ) );
  21. require_once(DEDEADMIN."/../include/common.inc.php");
  22. require_once(DEDEINC."/arc.partview.class.php");
  23. /*
  24. $row = $dsql->GetOne("Select * From dede_homepageset");
  25. $dsql->Close();
  26. $templet=$row['templet'];
  27. $position=$row['position'];
  28. */
  29. Templet $ = "tnbjh / index .htm" ; // This is the home page template location is currently dede first face default position.
  30. $position = "../index.html";
  31. $homeFile = dirname(__FILE__)."/".$position;
  32. $homeFile = str_replace("\", "/", $homeFile );
  33. $homeFile = str_replace( "//", "/", $homeFile );
  34. $ pv = new Coast View ( ) ;
  35. $pv ->SetTemplet( $cfg_basedir.$cfg_templets_dir."/".$templet );
  36. $pv -> SaveToHtml( $homeFile );
  37. $pv -> Close();
  38. $file = fopen( $fpath, "w");
  39. fwrite( $file, "<?php ");
  40. fwrite( $file,"$last_time=".time()."; ");
  41. fwrite( $file, '?>' );
  42. fclose( $file );
  43. }
  44. ?>

Then we need to introduce the following code on the first page of the template code that head tag, that is, the introduction of the php file:

  1. <script src="/plus/autoindex.php" language="javascript"></script>

Once completed click generated in the background - Update home page. So that we can achieve Home contents regular automatic updates, be sure to look at the note above, time is in seconds, the default 3600 seconds is one hour, you can change yourself.

Guess you like

Origin www.cnblogs.com/app345/p/11775628.html