zoukankan      html  css  js  c++  java
  • PHPCMS V9 栏目列表调用文章点击量及评论数量方法

    很多朋友在用Phpcms做站时,具体需要在列表页、首页调用文章列表调用文章的点击量和评论排行,那么怎么才能做到在Phpcms v9首页、频道页、列表页、推荐位等页面获取文章浏览量和评论统计呢?
    原因起于phpcms官方默认的模版没有在列表页面调用过文章点击量和评论数量,而且文章的内页调用浏览量hit的方法不适用于列表页。
    下面分享代码:
    
    一、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}
     
  • 相关阅读:
    最大子数组求和并进行条件组合覆盖测试
    Ubuntu 16.04 c++ Google框架单元测试
    The directory '/home/stone/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If execu
    Problem executing scripts APT::Update::Post-Invoke-Success 'if /usr/bin/test -w /var/cache/app-info -a -e /usr/bin/appstreamcli; then appstreamcli refresh > /dev/null; fi'
    个人博客作业三:微软小娜APP的案例分析
    补交 作业一
    补交 作业二:个人博客作业内容:需求分析
    嵌入式软件设计第12次实验报告
    嵌入式软件设计第11次实验报告
    嵌入式软件设计第10次实验报告
  • 原文地址:https://www.cnblogs.com/qhorse/p/5018691.html
Copyright © 2011-2022 走看看