PHPCMS 自定义全站热门文章排行函数
发表时间: 2015-10-13 11:49:57 | 浏览次数:
1.打开 phpcms\modules\content\classes\content_tag.class.php2.在里面添加以下代码:
/** * junqihits 站点点击排行 * @param $data */ function junqihits($data){ if(empty($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; }
调用代码:
{pc:content action="sitehits" siteid="1" num="10" order="views DESC" cache="3600"} {loop $data $r}{$r[title]} {/loop} {/pc}
(转载请注明:转自http://www.lrfun.com)
上一篇:PHPCMS 修改SEO标题 单网页SEO设置标题如何读取
下一篇:PHPCMS 调用自定义选项里的值