php 记录文章浏览次数,phpcms v9获取文章被浏览次数和被评论次数

36c50345316ec6f87c9e47c9f0089677.png

在list页(加在loop中)

{php $db = pc_base::load_model('hits_model'); $_r = $db->get_one(array('hitsid'=>'c-'.$modelid.'-'.$r[id])); $views = $_r[views];}

{php $comment_tag = pc_base::load_app_class("comment_tag", "comment"); $comment_total = $comment_tag->count(array('commentid'=>'content_'.$catid.'-'.$r[id].'-'.$modelid));}

点击:{$views} 评论数:{if $comment_total}{$comment_total}{else}0{/if}

若以上评论数结果为0,则使用下面的语句:

{php $comment_tag = pc_base::load_app_class("comment_tag", "comment"); $comment_total = $comment_tag->count(array('commentid'=>'content_'.$catid.'-'.$r[id].'-'.$siteid));}

在category页

{php $db = pc_base::load_model('hits_model'); $_r = $db->get_one(array('hitsid'=>'c-'.$modelid.'-'.$v[id])); $views = $_r[views]; }

{php $comment_tag = pc_base::load_app_class("comment_tag", "comment"); $comment_total = $comment_tag->count(array('commentid'=>'content_'.$v[catid].'-'.$v[id].'-'.$modelid));}

在首页

{pc:content action="lists" catid="$r[catid]" num="5" order="id DESC" return="info"}

{php $categorys = getcache('category_content_'.$siteid,'commons');}

{loop $info $v}

{php $category = $categorys[$v[catid]];}

{php $modelid = $category['modelid'];}

{php $db = pc_base::load_model('hits_model'); $_r = $db->get_one(array('hitsid'=>'c-'.$modelid.'-'.$v[id])); $views = $_r[views]; }

{php $comment_tag = pc_base::load_app_class("comment_tag", "comment"); $comment_total = $comment_tag->count(array('commentid'=>'content_'.$v[catid].'-'.$v[id].'-'.$modelid));}

点击:{$views} 评论:{if $comment_total}{$comment_total}{else}0{/if}

{/loop}

{/pc}

在推荐位

{pc:content action="position" posid="2" order="listorder DESC" num="4"}

{php $categorys = getcache('category_content_'.$siteid,'commons');}

{loop $data $r}

{php $category = $categorys[$r[catid]];}

{php $modelid = $category['modelid'];}

{php $db = pc_base::load_model('hits_model'); $_r = $db->get_one(array('hitsid'=>'c-'.$modelid.'-'.$r[id])); $views = $_r[views]; }

{php $comment_tag = pc_base::load_app_class("comment_tag", "comment"); $comment_total = $comment_tag->count(array('commentid'=>'content_'.$r[catid].'-'.$r[id].'-'.$modelid));}

点击:{$views} 评论:{if $comment_total}{$comment_total}{else}0{/if}

{/loop}

{/pc}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值