A-A+

Phpcms V9 点击量排行调用方法

2015年05月19日 PHP开源系统 评论 3 条 阅读 126 views 次

网站文章的点击量排行列表是较常见的了,基本上稍大一点的网站都有其文章点击排行,热门文章排行等这样的热门功能,甚至在个人博客站 wp 中就更常见了,而在 phpcms v9 中却只提供了当前栏目列表中的文章点击排行,而没有提供全站文章排行的代码,想要在phpcms v9 首页频道进行文章点击量排行就只能进行二次开发了,下面夏日博客把要进行二次开发的代码分享下来,其实也是很简单的。

首先调用的标签代码如下:

  1. {pc:content action=”sitehits” siteid=”4″ num=”10″ order=”views DESC” cache=”3600″}  
  2. {loop $data $r}  
  3. {$r[title]}  
  4. {/loop}  
  5. {/pc}  

另外我们还需要修改 phpcms 里模型代码以适用其上面的调用标签,打开 phpcms\modules\content\classes\content_tag.class.php 文件,在里面添加一个函数,代码如下:

  1. /** 
  2. * sitehits站点点击排行 
  3. * @param $data 
  4. */  
  5. function sitehits($data){  
  6. if(emptyempty($data['siteid'])) return false;  
  7. $siteid = intval($data['siteid']);  
  8. $this->hits_db = pc_base::load_model(‘hits_model’);  
  9. $category_content = getcache(‘category_content’,'commons’);  
  10. $catid = ”;  
  11. //获取站点下所有栏目ID  
  12. foreach($category_content as $key=>$val){  
  13. if($val==$siteid){  
  14. $catid .= $comma.$key;  
  15. $comma=’,';  
  16. }  
  17. }  
  18.   
  19. //获取点击排行  
  20. $r = $this->hits_db->select(‘catid in(‘.$catid.’)',’hitsid’,$data['limit'],$data['order']);  
  21. $return = array();  
  22. $sitemodel_model_db = pc_base::load_model(‘sitemodel_model’);  
  23. $this->db_config = pc_base::load_config(‘database’);  
  24. $tablepre = $this->db_config['default']['tablepre'];  
  25. foreach($r as $key){  
  26. preg_match_all(‘/-(\d+)-/’,$key['hitsid'],$modelid);  
  27. $id = substr($key['hitsid'],(strpos($key['hitsid'],’-',2)+1));  
  28. $tablename = $sitemodel_model_db->get_one(array(‘modelid’=>$modelid[1][0]),’tablename’);  
  29. $this->db->table_name = $tablepre.$tablename['tablename'];  
  30. $return[] = array_merge($return,$this->db->get_one(array(‘id’=>$id)));  
  31. }  
  32. return $return;  
  33. }  

OK,v9首页频道调用点击量排行文章就已经做完了,下面夏日博客再分享一些其它的点击排行调用方法,都是一些较实用的代码。

当天帖子点击排行调用方法:

  1. {php $historytime = mktime(0, 0, 0, date('m', TIME), date('d', TIME), date('Y', TIME));}  
  2. {get sql="select p.*,t.* from phpcms_content p,phpcms_content_count t where p.contentid=t.contentid and p.status=99 and p.inputtime>=$historytime order by t.hits desc" rows="10" return="v"}  
  3. 标题及链接:<a herf="{$v[url]}" >{$v[title]}</a>点击数:{$v[hits]} {/get}  

本周帖子点击排行调用方法:

  1. <?php $week = gmdate('w', TIME) - 1;  
  2. $week = $week != -1 ? $week : 6; $historytime = mktime(0, 0, 0, date('m', TIME), date('d', TIME) - $weekdate('Y', TIME)); ?>  
  3. {get sql="select p.*,t.* from phpcms_content p,phpcms_content_count t where p.contentid=t.contentid and p.status=99 and p.inputtime>=$historytime order by t.hits desc" rows="10" return="v"}  
  4. 标题及链接:<a herf="{$v[url]}" >{$v[title]}</a>点击数:{$v[hits]}  
  5. {/get}  

本月帖子点击排行调用方法:

  1. {php $historytime = mktime(0, 0, 0, date('m', TIME), 1, date('Y', TIME));}  
  2. {get sql="select p.*,t.* from phpcms_content p,phpcms_content_count t where p.contentid=t.contentid and p.status=99 and p.inputtime>=$historytime order by t.hits desc" rows="10" return="v"}  
  3. 标题及链接:<a herf="{$v[url]}" >{$v[title]}</a>点击数:{$v[hits]}  
  4. {/get}  

以上代码当然可以自定义,48小时点击:dayviews、day=2 本月点击:monthviews、day=48。

相信上面都是一些较常用的代码了,把这些代码放置到我们适合的位置就显示没哪么单调了。

标签:

3 条留言  访客:3 条  博主:0 条

  1. Meekdai

    Phpcms V9 就是你用的这个吧?

    • smiling

      我目前用的是 WP。

  2. Me.稀奇

    😯 来看看老盆友····

给我留言