帝国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><?}?>

https://www.webkfz.com/rjjc/34382.html

posted @ 2020-06-18 23:38  kuba8  阅读(316)  评论(0编辑  收藏  举报