PHPCMS全站文章点击排行2个例子
发布:smiling 来源: PHP粉丝网 添加日期:2014-12-05 13:46:16 浏览: 评论:0
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 { //开源软件:phpfensi.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} //开源软件:phpfensi.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}
Tags: PHPCMS全站文章 PHPCMS点击排行
相关文章
- ·Phpcms V9 调用全站文章排行的解决方案(2014-10-19)
- ·phpcms v9调用全站最新文章功能代码(2014-10-20)
- ·【phpcms-v9】如何通过{pc}标签获取全站文章内容?(2014-10-23)
- ·【phpcms-v9】phpcms-v9中get标签调用全站文章内容(2014-10-24)
- ·Phpcms v9调用全站文章排序榜实现方法(2015-03-24)
- ·phpcms v9笔记之全站点击排行调用方法(2014-10-24)
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)