2、调用统计点击的标签
3、最后,在写上这一句:"
phpcms v9增加文章随机点击数的方法
找到文件count.php(网站根目录/api)
查找第50行,找到这段代码$views
或者$views
Phpcms v9 实现首页,列表页,内容页调用点击量方法
1,首页调用点击量{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));}
- ·{str_cut($v['title'],40)} 点击:{$views} 评论:{if $comment_total}{$comment_total}{else}0{/if}
{/loop}
{/pc}
2,列表页调取点击量
{php $db = pc_base::load_model(‘hits_model’); $_r = $db->get_one(array(‘hitsid’=>’c-’.$modelid.’-’.$r[id])); $views = $_r[views]; }
点击:{$views}
列表页调用点击量例子:
<div class="subCont">
{pc:content action="lists" catid="$catid" num="10" order="id DESC" page="$page"}
<ul class="caselist">
{loop $data $r}
<li>
{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));}
<div class="cmsyouunit">
<h1><a href="{$r[url]}" target="_blank" title="{$r[title]}" class="title">{$r[title]}</a></h1>
<h4>发表于{date('Y-m-d H:i:s',$r[inputtime])}|{if $views}{$views}次阅读{else}哇,这是崭新的文章!{/if}|{if $comment_total}{$comment_total}{else}0{/if}条评论</h4>
<table><tr>
<td class="preview">{if $r[thumb]}<a href="{$r[url]}" target="_blank" class="img"><img src="{thumb($r[thumb])}" width="100" height="75" alt="{$r[title]}" /></a>{/if}</td>
<td class="desc">{str_cut(strip_tags($r[description]), 398)}
<div class="tag">
{php $keywords = explode(' ',$r[keywords]);}
{loop $keywords $keyword}
<a href="{APP_PATH}index.php?m=content&c=tag&catid={$catid}&tag={urlencode($keyword)}" target="_blank">{$keyword}</a>
{/loop}
</div>
</td>
</tr></table>
</div>
</li>
{/loop}
</ul>
{/pc}
</div>
3, 内容页调取点击量
<\script type="text/javascript" src="{JS_PATH}jquery.min.js">
<\span id="hits"><\script language="JavaScript" src="{APP_PATH}api.php?op=count&id={$id}&modelid={$modelid}"><\/span>