PHPCMS V9 点击量排行调用方法

时间:2024-01-17 12:05:26
首先调用的标签代码如下:
{pc:content action=”sitehits” siteid=”4″ num=”10″ order=”views DESC” cache=”3600″}
  {loop $data $r}
    {$r[title]}
  {/loop}
{/pc}

另外我们还需要修改 phpcms 里模型代码以适用其上面的调用标签,
打开 phpcms\modules\content\classes\content_tag.class.php 文件,在里面添加一个函数,
代码如下:
/**
* sitehits站点点击排行
* @param $data
*/
function sitehits($data){
  if(emptyempty($data['siteid'])) return false;
  $siteid = intval($data['siteid']);
  $this->hits_db = pc_base::load_model('hits_model');
  $category_content = getcache('category_content','commons');
  $catid = '';
  //获取站点下所有栏目ID
  foreach($category_content as $key=>$val){
    if($val==$siteid){
      $catid .= $comma.$key;
      $comma=',';
    }
  }
  //获取点击排行
  $r = $this->hits_db->select('catid in('.$catid.')','hitsid',$data['limit'],$data['order']);
  $return = array();
  $sitemodel_model_db = pc_base::load_model('sitemodel_model');
  $this->db_config = pc_base::load_config('database');
  $tablepre = $this->db_config['default']['tablepre'];
  foreach($r as $key){
    preg_match_all('/-(\d+)-/',$key['hitsid'],$modelid);
    $id = substr($key['hitsid'],(strpos($key['hitsid'],'-',2)+1));
    $tablename = $sitemodel_model_db->get_one(array('modelid' => $modelid[1][0]),'tablename');
    $this->db->table_name = $tablepre.$tablename['tablename'];
    $return[] = array_merge($return,$this->db->get_one(array('id' => $id)));
  }
  return $return;
}

OK,v9首页频道调用点击量排行文章就已经做完了,下面再分享一些其它的点击排行调用方法,都是一些较实用的代码。
当天帖子点击排行调用方法:
{php $historytime = mktime(0, 0, 0, date('m', TIME), date('d', TIME), date('Y', TIME));}
{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"}
标题及链接:<a herf="{$v[url]}" >{$v[title]}</a>点击数:{$v[hits]} {/get}

本周帖子点击排行调用方法:
<?php $week = gmdate('w', TIME) - 1;
$week = $week != -1 ? $week : 6; $historytime = mktime(0, 0, 0, date('m', TIME), date('d', TIME) - $week, date('Y', TIME)); ?>
{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"}
标题及链接:<a herf="{$v[url]}" >{$v[title]}</a>点击数:{$v[hits]}
{/get}

本月帖子点击排行调用方法:
{php $historytime = mktime(0, 0, 0, date('m', TIME), 1, date('Y', TIME));}
{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"}
标题及链接:<a herf="{$v[url]}" >{$v[title]}</a>点击数:{$v[hits]}
{/get}
以上代码当然可以自定义,48小时点击:dayviews、day= 本月点击:monthviews、day=。