phpcms获取文章被浏览次数和被评论次数
[ 2016/03/27, Phpcms , 2912阅, 0评 ]

QQ截图20160327210534.jpg

在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"}
<ul>
  {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));} 
<li>点击:{$views} 评论:{if $comment_total}{$comment_total}{else}0{/if}</li>
{/loop}
</ul>
{/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));}
<li>点击:{$views} 评论:{if $comment_total}{$comment_total}{else}0{/if}</li>
{/loop} 
{/pc}

有朋自远方来...评论一下呗O(∩_∩)O