点击量

来源:官方· 作者 jizhicms· 22次点击 · 5个月前

基本使用

点击量一般存储在 hits 字段中,在内容模型和商品模型,以及自定义模型都会自带这个字段。


列表中显示点击量

{foreach $lists as $v}
点击量/阅读量:{$v['hits']}
{/foreach}


自增操作

在详情页里面,经常需要用到自增操作,就是每次访问的时候自动增加一次点击量


文章模型详情页

{fun incrData('article',$jz['id'],'hits')}


商品模型详情页

{fun incrData('product',$jz['id'],'hits')}


自定义模型详情页

{fun incrData($jz['molds'],$jz['id'],'hits')} //通用


JS操作自增

上面的自增是使用函数实现,但是很多情况下,需要生成静态HTML的时候,上面的方法就不起作用了,那么就要js操作自增。

<span id="read-num">热度 {$jz['hits']}</span>

<script>
$.get('/common/gohits?molds={$jz['molds']}&id={$jz['id']}',function(r){
   $("#read-num").html('热度 '+r);
   })
</script>


有可能文章模型会不行,把 $jz['molds'] 换成 'article'


被收藏 0  ∙  0 赞  
加入收藏
0 回复  
善言善语 (您需要 登录 后才能回复 没有账号 ?)

请先登录网站