phpcms如何调用热门标签tag?

Phpcms V9调用热门TAG要使用Get SQL语句,调用tag数据库,loop循环输出;但V9版本的PHPCMS默认没有完善tag功能,必须下载一个插件;

插件如下:

http://files.cnblogs.com/xltf/phpcms_tag.rar

首先将压缩包解压以后将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标签模块;点安装;再重建引索即可

18103552-60bfb1d6050840c6ae5f9632a1e035ab(我这里已经安装,所以显示的是卸载)

 

最后再使用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[tag]}&time=all">{$r[tag]}</a>| 
{/loop}
{/pc}
文章链接:,本站部分内容来自互联网,如不慎侵害的您的权益,请告知,我们将尽快删除!

发表评论