dedecms首页调用随机文章及自动更新功能实例
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>本文实例讲述了dedecms首页调用随机文章及自动更新功能的实现方法。分享给大家供大家参考。具体实现方法如下:</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
我们知道织梦多数情况下是生成静态的html文件的,这样一方面可以减少服务器的负荷,另一方面也是为了优化,但是织梦本身静态要手动更新生成,不是自动的,今天我们就来说一下怎样实现自动更新.</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
(1)调用随机文章:</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
织梦给出了随机文章调用的参数如下:</p>
<blockquote>
<ol class="dp-xml">
<li class="alt">
<span><span>{dede:arclist </span><span class="attribute">sort</span><span>=</span><span class="attribute-value">'rand'</span><span> </span><span class="attribute">titlelen</span><span>=</span><span class="attribute-value">48</span><span> </span><span class="attribute">row</span><span>=</span><span class="attribute-value">16</span><span>} </span></span>
</li>
<li>
<span><span class="tag"><</span><span class="tag-name">li</span><span class="tag">></span><span class="tag"><</span><span class="tag-name">a</span><span> </span><span class="attribute">href</span><span>=</span><span class="attribute-value">""</span><span> </span><span class="attribute">title</span><span>=</span><span class="attribute-value">""</span><span> </span><span class="attribute">target</span><span>=</span><span class="attribute-value">"_blank"</span><span class="tag">></span><span></span><span class="tag"></</span><span class="tag-name">a</span><span class="tag">></span><span class="tag"></</span><span class="tag-name">li</span><span class="tag">></span><span> </span></span>
</li>
<li class="alt">
<span>{/dede:arclist} </span>
</li>
</ol>
</blockquote>
<p>
<span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>(2)置定时自动更新文件:</span></p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
复制下面代码,粘贴到一个新文件中,命名为:autoindex.php,上传到ftp的plus文件夹中,看清楚一点是plus文件夹中,错了位置不会生效.<br>
</p>
<div class="msgheader" style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
<div class="right">
<span><u>复制代码</u></span>
</div>
<p>
代码如下:</p>
</div>
<div class="msgborder" id="phpcode4" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
<?php <br>
function sp_input( $text ) <br>
{ <br>
$text = trim( $text ); <br>
$text = htmlspecialchars( $text ); <br>
if (!get_magic_quotes_gpc()) <br>
return addslashes( $text ); <br>
else <br>
return $text; <br>
} <br>
$autotime = 3600;//自动更新时间,单位为秒,这里我设为一小时,大家可以自行更改。 <br>
$fpath = "../data/last_time.inc";//记录更新时间文件,如果不能达到目的,请检查是否有读取权限。 <br>
include( $fpath ); <br>
if( emptyempty($last_time)) <br>
$last_time = 0; <br>
if( sp_input($_GET['renew'])=="now") <br>
$last_time = 0; <br>
if((time()-$last_time)>=$autotime ) <br>
{ <br>
define('DEDEADMIN', ereg_replace("[/\]{1,}",'/',dirname(__FILE__) ) ); <br>
require_once(DEDEADMIN."/../include/common.inc.php"); <br>
require_once(DEDEINC."/arc.partview.class.php"); <br><br>
$templet = "tnbjh/index.htm";//这里是首页模板位置,当前是dede默认首面位置。 <br>
$position = "../index.html"; <br>
$homeFile = dirname(__FILE__)."/".$position; <br>
$homeFile = str_replace("\", "/", $homeFile ); <br>
$homeFile = str_replace( "//", "/", $homeFile ); <br>
$pv = new PartView(); <br>
$pv ->SetTemplet( $cfg_basedir.$cfg_templets_dir."/".$templet ); <br>
$pv -> SaveToHtml( $homeFile ); <br>
$pv -> Close();<br>
$file = fopen( $fpath, "w"); <br>
fwrite( $file, "<?php "); <br>
fwrite( $file,"$last_time=".time()."; "); <br>
fwrite( $file, '?>' ); <br>
fclose( $file ); <br>
} <br>
?></div>
<p>
<br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>然后我们需要在首页的模版代码head标签中加入一段代码:</span></p>
<div class="msgheader" style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
<div class="right">
<span><u>复制代码</u></span>
</div>
<p>
代码如下:</p>
</div>
<div class="msgborder" id="phpcode5" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
</div>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
然后点击后台生成,更新首页,到此就ok了啊.</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
希望本文所述对大家的dedecms建站有所帮助。</p>
頁:
[1]