最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
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"}
{loop $data $key $val} {/loop} {/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} |
相关文章
- 人们熟悉的寄居蟹属于以下哪种分类 神奇海洋11月21日答案 11-21
- 第五人格11.22共研服有什么更新 11月22日共研服更新内容介绍 11-21
- 原神恰斯卡怎么培养 11-21
- 无期迷途四星装束是谁 11-21
- 王者荣耀帝丹高中校服怎么获得 11-21
- 光遇姆明季后续版本怎么玩 11-21