php教学视频(Phpcms V9 栏目列表调用文章点击量及评论数量方法)

feifei123 发布于 2025-02-25 阅读(7)

很多朋友在用Phpcms做站时,具体需要在列表页、首页调用文章列表调用文章的点击量和评论排行,那么怎么才能做到在Phpcms v9首页、频道页、列表页、推荐位等页面获取文章浏览量和评论统计呢?原因起于phpcms官方默认的模版没有在列表页面调用过文章点击量和评论数量,而且文章的内页调用浏览量hit的方法不适用于列表页。

下面是具体的代码,分享在此,具体在列表页调用文章点击量的演示在这里:http://www.cmsyou.com/support/一、Phpcms列表页面取得文章点击量及评论数量:{pc:content action="lists" catid="$catid" num="25" order="id DESC" page="$page" moreinfo="1"} {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));} {date(Y-m-d H:i:s,$r[inputtime])}·{$r[title]} 点击:{$views} 评论数:{if $comment_total}{$comment_total}{else}0{/if}{/loop} {$pages} {/pc}。

二、Phpcms频道页面取得文章点击量及评论数量:{pc:content action="lists" catid="$v[catid]" num="5" order="id DESC"} {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));} {$v[title]}点击:{$views}评论数:{if $comment_total}{$comment_total}{else}0{/if} {/loop} {/pc}

三、Phpcms首页面取得文章点击量及评论数量:{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}

四、Phpcms推荐位取得文章点击量及评论数量:{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));} {str_cut($r[title],36,)} 点击:{$views} 评论:{if $comment_total}{$comment_total}{else}0{/if}

{if $n==1}{/if}{str_cut($r[description],112)}

{/loop} {/pc}

Enjoy it!20130228更新:要多谢来自QQ上的网友Huang,他在看了上面的说明后,觉得在统计页面还需要加上统计的JS,这是对的需要在show.html、show_picture.html等模板文件底部加入以下代码:。

这是官方默认模版里边自带的,别忘了加上这个!

谢谢Huang提醒我们更新文章!

亲爱的读者们,感谢您花时间阅读本文。如果您对本文有任何疑问或建议,请随时联系我。我非常乐意与您交流。

标签:  点击 评论 文章 调用 列表 

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。