phpcms实现在首页列表页频道页调用评论数代码分

最近在用PHPCMS做一个项目,需要在首页,频道页,列表页等位置调用评论数,研究了一下,现在把代码放出来给大家分享

废话不多说,直接上代码
一、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));}
<li><span class="rt">{date('Y-m-d H:i:s',$r[inputtime])}</span>·<a href="{$r[url}" target="_blank"{title_style($r[style])}>{$r[title]}</a> 点击:{$views} 评论数:{if $comment_total}{$comment_total} {else}0{/if}</li>
{/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));}
<li><a href="{$v[url]}" target="_blank"{title_style($v[style])}>{$v[title]}</a>点击:{$views}评论数:{if $comment_total}{$comment_total}{else}0{/if}</li>
{/loop}
{/pc}

三、Phpcms首页面取得文章点击量及评论数量:


{pc:content action="lists" catid="$r[catid]" num="5" order="id DESC" return="info"}
{php $categorys = getcache('category_content_'.$siteid,'commons');}
<ul class="list lh24 f14">
{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']}"{title_style($v[style])}>{str_cut($v['title'],40)}</a> 点击:{$views} 评论:{if $comment_total}{$comment_total}{else}0{/if}</li>
{/loop}
</ul>
{/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));}
<h4 class="blue"><a href="{$r[url]}" title="{$r[title]}">{str_cut($r[title],36,'')}</a> 点击:{$views} 评论:{if $comment_total}{$comment_total}{else}0{/if}</h4>
<p>{if $n==1}<img src="{thumb($r[thumb],90,60)}" width="90" height="60"/>{/if}{str_cut($r[description],112)}</p>
<div class="bk20 hr"><hr /></div>
{/loop}
{/pc}

极客网企业会员

免责声明:本网站内容主要来自原创、合作伙伴供稿和第三方自媒体作者投稿,凡在本网站出现的信息,均仅供参考。本网站将尽力确保所提供信息的准确性及可靠性,但不保证有关资料的准确性及可靠性,读者在使用前请进一步核实,并对任何自主决定的行为负责。本网站对有关资料所引致的错误、不确或遗漏,概不负任何法律责任。任何单位或个人认为本网站中的网页或链接内容可能涉嫌侵犯其知识产权或存在不实内容时,应及时向本网站提出书面权利通知或不实情况说明,并提供身份证明、权属证明及详细侵权或不实情况证明。本网站在收到上述法律文件后,将会依法尽快联系相关文章源头核实,沟通删除相关内容或断开相关链接。