zblog读者墙数据调用代码
今天开发模板,正好需要读者墙代码,自己写了一个,比网上流传的代码简单高效,排序方式是评论最多的用户在前
function readers(){
global $zbp;
$limit = 100;
$list = array();
$sql = $zbp->db->sql->get()->select($zbp->table['Comment'])->column('comm_Name,comm_Email,comm_AuthorID,count(*)')->groupby('comm_Name,comm_Email,comm_AuthorID')->orderBy(array('count(*)' => 'DESC'))->limit($limit)->sql;
foreach($zbp->db->Query($sql) as $value){
$value = array_values($value);
$list[] = array(
'member' => $zbp->GetMemberByID($value[2]),
'name' => $value[0],
'email' => $value[1],
'count' => $value[3],
);
}
return $list;
}
模板里调用方法:
{foreach readers() as $value} 用户:{$value['member']->StaticName} 名称:{$value['name']} 邮箱:{$value['email']} 评论数量:{$value['count']} {/foreach}