PHPCMS v9 默认只调用当前栏目的文章排行,却没有调用全站文章排行的代码,现在分享给大家两个调用的方法,如下:
方法一:
打开phpcmsmodulescontentclassescontent_tag.class.php,在里面添加以下代码:
/** * sitehits站点点击排行 PHPCMS吧 * @param $data */ function sitehits($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} <a href="{$r[url]}" target="_blank">{$r[title]}</a> {/loop} {/pc}
方法二:
在需要调用的地方添加以下代码即可:
{pc:get sql="select url,title,inputtime,dayviews FROM v9_news,v9_hits WHERE CONCAT('c-1-',v9_news.id)=v9_hits.hitsid order by weekviews desc" num="10" siteid="$siteid"} {loop $data $r} <li><span class="num{$n}">{$n}</span><a href="{$r[url]}" title="{$r[title]}"{title_style($r[style])} target="_blank">{$r[title]}</a></li> {/loop} {/pc}
其中c-1-中的1是模型ID(默认的文章模型),也可以实现自定义模型的,代码中的weekviews代表调用一周热门文章,大家还可以将其替换成monthviews调用一个月的热门文章等。