这样做当然可以方便的调用出来文章点击率,但是有一点就是太复杂了,压根记不住,所以为了精简代码,特别对list标签做个整改:
- {php
- $db = pc_base::load_model('hits_model');
- $_r = $db->get_one(array('hitsid'=>'c-'.$modelid.'-'.$r[id]));
- $views = $_r[views];
- }
(1)找到文件phpcmsmodulescontentclassescontent_tag.class.php,找到代码:
找到list方法的最后一行,在return $return;之前加入代码:
- public function lists($data) {
- /是否调用点击
- $siteids = getcache('category_content','commons');
- if(!$siteids[$catid]) return false;
- $siteid = $siteids[$catid];
- $CATEGORYS = getcache('category_content_'.$siteid,'commons');
- if (isset($data['hits']) && intval($data['hits']) == 1){
- $hits_db = pc_base::load_model("hits_model");
- foreach ($return as $k => $r) {
- $modelid = $CATEGORYS[$r['catid']]['modelid'];
- $_r = $hits_db ->get_one(array('hitsid' => 'c-'.$modelid.'-'.$r[id]));
- $return[$k]['views'] = $_r["views"];
- }
- }
这样前端就可以直接通过hits="1"调用,不写或者为0都表示不调用点击
- {pc:content action="lists" hits="1" catid="8" num="10" order="listorder DESC"}
- {loop $data $r}
- 点击:{$r[views]}
(2)找到public function position($data) {方法在最后一行return $array;之前加入代码
- //是否调用点击
- $CATEGORYS = getcache('category_content_'.$siteid,'commons');
- if (isset($data['hits']) && intval($data['hits']) == 1){
- $hits_db = pc_base::load_model("hits_model");
- foreach ($array as $k => $r) {
- $modelid = $CATEGORYS[$r['catid']]['modelid'];
- $_r = $hits_db ->get_one(array('hitsid' => 'c-'.$modelid.'-'.$r[id]));
- $array[$k]['views'] = $_r["views"];
- }
- }
这样就可以在推荐位列表中通过hits="1"直接调用点击了,
这么一改再也不用担心记不住调用点击的代码了