PHPCMS自带的点击排行标签不支持全站文章点击排行,必须输入类别,可以把自带的点击标签复制一份稍加修改一下支持全站文章点击排行,代码如下:
- /**
- * 全站排行榜标签
- * @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 { //开源软件:Vevb.com
- $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"}
- <ul class="softolist">
- {loop $data $key $val}
- <li> <a href="{$val['url']}" title="{$val['title']}">{$val['title']}</a></li>
- {/loop} //开源软件:Vevb.com
- </ul>
- {/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}
新闻热点
疑难解答