一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

PHPCMS全站文章点击排行2个例子

时间:2022-06-25 16:29:10 编辑:袖梨 来源:一聚教程网

例子

 代码如下 复制代码
/**
 * 全站排行榜标签
 * @param $data
 */
public function hits_all($data){
 $this->modelid = 12;//这里就写成固定的,模型id去后台模型管理找
 $this->hits_db = pc_base::load_model('hits_model');
 $this->db->set_model($this->modelid);
 $this->tablename = $this->db->table_name;
 $sql = $desc = $ids = '';
 $array = $ids_array = array();
 $order = $data['order'];
 $hitsid = 'c-'.$this->modelid.'-%';
 $sql = "hitsid LIKE '$hitsid'";
 if(isset($data['day'])) {
  $updatetime = SYS_TIME-intval($data['day'])*86400;
  $sql .= " AND updatetime>'$updatetime'";
 }
 $hits = array();
 $result = $this->hits_db->select($sql, '*', $data['limit'], $order);
 foreach ($result as $r) {
  $pos = strpos($r['hitsid'],'-',2) + 1;
  $ids_array[] = $id = substr($r['hitsid'],$pos);
  $hits[$id] = $r;
 }
 $ids = implode(',', $ids_array);
 if($ids) {
  $sql = "status=99 AND id IN ($ids)";
 } else {
  $sql = '';
 }
 $this->db->table_name = $this->tablename;
 $result = $this->db->select($sql, '*', $data['limit'],'','','id');
 foreach ($ids_array as $id) {
  if($result[$id]['title']!='') {
   $array[$id] = $result[$id];
   $array[$id] = array_merge($array[$id], $hits[$id]);
  }
 }
 return $array;
}


调用的时候:

 代码如下 复制代码

 {pc:content  action="hits_all" order="weekviews DESC" num="10"}
 


 {/pc}

例2

①打开phpcmsmodulescontentclassescontent_tag.class.php文件;
②找个位置添加以下代码(首行时间可以自由修改,方便后期查询):
 

 代码如下 复制代码
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_contentas$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($ras$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;
}

③备份文件,以防后期pc程序升级时被覆盖;

④前端页面模板调用方法(示例):

 
如下:

 代码如下 复制代码

{pc:content action="sitehits" siteid="4" num="10" order="views DESC" cache="3600"} {loop $data$r}
"{$r[url]}" target="_blank">{$r[title]}
{/loop}
{/pc}

热门栏目