帝国CMS随机调用栏目
复制代码
[e:loop={'select * from [!db.pre!]enewsclass where bclassid in(1) order by rand() desc limit 10',10,24,0}]
<?
if($bqr['classurl']=='')
{
$sccurl=$public_r['newsurl'].$bqr['classpath']."/";
}
else
{
$sccurl=$bqr['classurl']."/";
}
?>
<a target="_blank" href="<?=$sccurl?>"><?=$bqr['classname']?></a> |
[/e:loop]
复制代码
帝国cms随机调用N个终极栏目
方法一:(适用于栏目非常多的情况下,效率比较好)
复制代码
<?phpfunction IslastClassid(){
global $class_r;
foreach ($class_r as $k => $v) {
if ($v['islast'] == 1) {
$all[]= $v['classid'];
}
}
$rand_key = array_rand($all , 5);//随机取5个
foreach ($rand_key as $k => $v) {
$classall.= $v.',';
}
$classall = trim($classall , ',');
$classall = $classall ? $classall : 0 ;
return $classall;}$class_sql=$empire->query('select * from '.$dbtbpre.'enewsclass where classid in ('.IslastClassid().') order by myorder');while($class_row=$empire->fetch($class_sql)){$classurl=sys_ReturnBqClassUrl($class_r[$class_row['classid']]); //栏目链接地址?><li><a href="<?=$classurl?>"><?=$class_row['classname']?></a></li><?}?>
复制代码
方法二:(栏目不多的情况下可以使用)
<?php$class_sql=$empire->query('select * from '.$dbtbpre.'enewsclass where islast=1 order by RAND() LIMIT 5');while($class_row=$empire->fetch($class_sql)){$classurl=sys_ReturnBqClassUrl($class_r[$class_row['classid']]); //栏目链接地址?><li><a href="<?=$classurl?>"><?=$class_row['classname']?></a></li><?}?>