给dede的include标签增加一个随机数功能
看了一篇优化DEDE的文章,其中有将文章模板的arclist去掉,也就是将推荐文章和热点文章的调用去掉
然后用自由列表先生成这些调用的静态文件,再在文章模板里引用一下就可以了
可是DEDE的引用只能引用一个页面,于是我想能不能随机引用一个文件呢
这样文章页面的 推荐文章和热点文章 不至于那么呆板 每次都是那几篇文章
于是我修改了DEDE的标签解释文件 include/dedetag.class.php 约419行
????$filename = ($CTag->GetAtt(‘file’)==” ? $CTag->GetAtt(‘filename’) : $CTag->GetAtt(‘file’) );
的后面增加
????//imxh修改,增加随机数目
????if ($CTag->GetAtt(‘rand’)){
????$num1=$CTag->GetAtt(‘rand’);
??????????????? $num1=explode(“,”,$num1);
????$num2=rand((int)$num1[0],(int)$num1[1]);
??????????????? $filename=preg_replace(“/[0-9].htm/is”,$num2.”.htm”,$filename);
????}
这样在引用文件里添加rand=’开始数字,结束数字’就可以了
比如我引用的
{dede:include? filename=”../../freelist/hot_2_1.html” ismake=’no’ rand=’1,3′ /}
将会随机引入 ../../freelist/hot_2_1.html? ../../freelist/hot_2_2.html?? ../../freelist/hot_2_3.html 中的一个文件
注意: filename=”../../freelist/hot_2_1.html”? 中.html前面一个必须是数字,就是吧这个数字替换的