极致CMS如何输出文章/商品点赞人数?
博主:紫藤心-迷途
浏览次数:1459次
计算文章/商品点赞人数:
function count_zan($tid,$id){ $sql = " likes like '%||".$tid.'-'.$id."||%' "; $count = M('member')->getCount($sql); return $count; }
注解:
$tid:当前栏目的ID
$id:当前文章/商品的ID
将上面的方法放入Conf/FunctionsExt.php扩展函数文件中,前台模板中使用:
文章/商品详情页中使用:
{fun count_zan($jz['tid'],$jz['id'])}
栏目列表(foreach $lists as $v),loop循环(as="v")中使用:
{fun count_zan($v['tid'],$v['id'])}
======================================================
v1.6.4更新
//计算点赞数
function jz_zan($tid,$id){ $sql = " likes like '%||".$tid.'-'.$id."||%' "; $count = M('member')->getCount($sql); return $count; }
//计算收藏数
function jz_collect($tid,$id){ $sql = " collection like '%||".$tid.'-'.$id."||%' "; $count = M('member')->getCount($sql); return $count; }
模板可以直接调用这两个方法
===============================================
扩展信息
输出所有点赞用户,暂时不支持变量传值,下面举例,输出栏目为1,ID为2的文章点赞用户
{loop table="member" like="||1-2||" as="v"}
用户名:{$v['username']}
用户头像:{$v['litpic']}
//其他信息根据数据库字段输出
{/loop}