Loading... Phpcms V9调用热门TAG要使用Get SQL语句,调用tag数据库,loop循环输出;但V9版本的PHPCMS默认没有完善tag功能,必须下载一个插件; 插件如下: [http://files.cnblogs.com/xltf/phpcms_tag.rar][1] 首先将压缩包解压以后将phpcms文件夹放到根目录覆盖原来的文件夹(其实所有的文件都是新建的) 然后打开`phpcms/model/content_model.class.php` 找到 if(!$isimport && $data['status']==99) { 在他的上面添加如下代码 // 添加到tags 表开始 if($systeminfo['keywords']){ $this->db_tags = pc_base::load_model('tags_model'); //$this->db_tags_content = pc_base::load_model('tags_content_model'); $keywords = strpos($systeminfo['keywords'], ',') !== false ? explode(',', $systeminfo['keywords']) : explode(' ', $systeminfo['keywords']); $sql = ''; foreach($keywords as $key){ if($this->db_tags->get_one("`tag`='$key'", 'tagid')){ $this->db_tags->query("UPDATE `phpcms_tags` SET `usetimes`=usetimes+1 WHERE tag='$key'"); }else{ $this->db_tags->query("INSERT INTO `phpcms_tags`(`tag`,`usetimes`,`lastusetime`,`lasthittime`)VALUES('$key',1,".SYS_TIME.",".SYS_TIME.")"); } $sql .= ",('$key','$urls[0]','$systeminfo[title]',$this->siteid,$modelid,$id,$systeminfo[catid],".SYS_TIME.")\n"; } if($sql){ $sql = "INSERT INTO `phpcms_tags_content` (`tag`,`url`,`title`,`siteid`,`modelid`,`contentid`,`catid`,`updatetime`) VALUES ".substr($sql, 1); $this->db_tags->query($sql); } } // 添加到 tags 表结束 找到下面的 $this->content_check_db->update($check_data,array('checkid'=>'c-'.$id.'-'.$this->modelid)); 在他的下面添加如下代码 // 添加到tags 表开始 if($systeminfo['keywords']){ $this->db_tags = pc_base::load_model('tags_model'); $this->db_tags_content = pc_base::load_model('tags_content_model'); $keywords = strpos($systeminfo['keywords'], ',') !== false ? explode(',', $systeminfo['keywords']) : explode(' ', $systeminfo['keywords']); $sql = ''; foreach($keywords as $key){ if(!$this->db_tags_content->get_one("`tag`='$key' AND `contentid` = $id AND `catid` =$systeminfo[catid] ", 'contentid')){ if($this->db_tags->get_one("`tag`='$key'", 'tagid')){ $this->db_tags->query("UPDATE `phpcms_tags` SET `usetimes`=usetimes+1 WHERE tag='$key'"); }else{ $this->db_tags->query("INSERT INTO `phpcms_tags`(`tag`,`usetimes`,`lastusetime`,`lasthittime`)VALUES('$key',1,".SYS_TIME.",".SYS_TIME.")"); } $sql .= ",('$key','$urls[0]','$systeminfo[title]',$this->siteid,$this->modelid,$id,$systeminfo[catid],".SYS_TIME.")\n"; } } if($sql){ $sql = "INSERT INTO `phpcms_tags_content` (`tag`,`url`,`title`,`siteid`,`modelid`,`contentid`,`catid`,`updatetime`) VALUES ".substr($sql, 1); $this->db_tags->query($sql); } } // 添加到 tags 表结束 然后进入后台管理模块;可以看到TAG标签模块;点安装;再重建引索即可 (我这里已经安装,所以显示的是卸载) 最后再使用Get SQL语句就可以把热门标签调用出来了; {pc:get sql="SELECT tag,hits FROM v9_tags order by hits desc" num="8"} <h2>热门标签</h2> {loop $data $r} <a href="{APP_PATH}index.php?m=search&c=index&a=init&typeid=1&q={$r<span class="label bg-light dk"></span>}&time=all">{$r<span class="label bg-light dk"></span>}</a>| {/loop} {/pc} [1]: http://files.cnblogs.com/xltf/phpcms_tag.rar Last modification:September 21, 2022 © Allow specification reprint Like 如果觉得我的文章对你有用,请随意赞赏