当前位置:主页 > 建站教程 > PHPCMS >

phpcms v9调用文章模型点击量及评论数量的方法

发布时间:2018-11-07 来源:互联网 浏览: 关键词:PHPCMS 文章模型 

1、首页调用文章模型点击量及评论数量:

{pc:content action="lists" catid="6" num="6" order="id DESC" return="info"}
{php $categorys = getcache('category_content_'.$siteid,'commons');}
<ul>
{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>
  <a href="{$v['url']}" target="_blank" title="{$v['title']}">{str_cut($v['title'],40)}</a>
  点击:{$views} 
  评论:{if $comment_total}{$comment_total}{else}0{/if}
</li>
{/loop}
</ul>
{/pc}

2、列表页调用文章模型点击量及评论数量:

{pc:content action="lists" catid="$catid" num="6" order="id DESC" page="$page" moreinfo="1"}
<ul>
{loop $data $r}
{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));}
<li>
  <a href="{$r[url]}" target="_blank" title="{$r[title]}">{$r[title]}</a> 
  点击:{$views} 
  评论数:{if $comment_total}{$comment_total} {else}0{/if}
</li>
{/loop}
</ul>
{$pages}
{/pc}

3、频道页调用文章模型点击量及评论数量:

{pc:content action="lists" catid="$catid" num="6" order="id DESC"}
<ul>
{loop $data $v}
{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>
  <a href="{$v[url]}" target="_blank" title="{$v[title]}">{$v[title]}</a>
  点击:{$views}
  评论数:{if $comment_total}{$comment_total}{else}0{/if}
</li>
{/loop}
</ul>
{/pc}

4、推荐位调用文章模型点击量及评论数量:

{pc:content action="position" posid="2" order="listorder DESC" num="6"}
{php $categorys = getcache('category_content_'.$siteid,'commons');}
<ul>
{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>
  <a href="{$r[url]}" title="{$r[title]}">{str_cut($r[title],36,'')}</a> 
  点击:{$views} 
  评论:{if $comment_total}{$comment_total}{else}0{/if}
</li>
{/loop}
</ul>
{/pc}

5、内容页调用文章模型点击量:
首先,引入如下js(head或body里均可以):
<script type="text/javascript" src="{JS_PATH}jquery.min.js"></script>
然后,在需要显示点击次数的地方加入如下代码(下边代码只显示点击量数字):
<span id="hits"></span>
最后,必须在<span id="hits"></span>后边引入如下js:
<script language="JavaScript" src="{APP_PATH}api.php?op=count&id={$id}&modelid={$modelid}"></script> 
责任编辑:MOKUGE
共有人阅读,期待你的评论!评论
骚年说点什么吧
  • 全部评论(0
    还没有评论,快来抢沙发吧!
Top