Discuz!门户文章增加标签tag功能教程

很对关于discuz门户文章标签的问题,由于discuz门户文章本身就没有标签功能,下面是手动增加tag功能的方法

添加一个tag模版

1、首先修改文章添加Tag模版:/template/default/portal/portalcp_article.htm

我们先要找到以下内容代码:

 

<span class="token operator"><</span>div <span class="token keyword">class</span><span class="token operator">=</span>”bm bml”<span class="token operator">></span> <span class="token operator"><</span>div <span class="token keyword">class</span><span class="token operator">=</span>”bm_h cl”<span class="token operator">></span> <span class="token tag"><span class="token punctuation"><</span>h2<span class="token punctuation">></span></span><span class="token punctuation">{</span>lang article_description<span class="token punctuation">}</span><span class="token tag"><span class="token punctuation"></</span>h2<span class="token punctuation">></span></span> <span class="token tag"><span class="token punctuation"></</span>div<span class="token punctuation">></span></span> <span class="token tag"><span class="token punctuation"><</span>div <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span>”bm_c”</span><span class="token punctuation">></span></span><span class="token plain-text"> <textarea id=”summary” name=”summary” cols=”80″ class=”pt” maxlength=”120″ style=”width: 98.7%; height: 51px;”>$article[summary]</span><span class="token tag"><span class="token punctuation"></</span>textarea<span class="token punctuation">></span></span> <span class="token tag"><span class="token punctuation"></</span>div<span class="token punctuation">></span></span> <span class="token tag"><span class="token punctuation"></</span>div<span class="token punctuation">></span></span>

然后在该代码下面添加以下内容

 

<span class="token operator"><</span>div <span class="token keyword">class</span><span class="token operator">=</span>”bm bml”<span class="token operator">></span>
<span class="token operator"><</span>div <span class="token keyword">class</span><span class="token operator">=</span>”bm_h cl”<span class="token operator">></span>
<span class="token tag"><span class="token punctuation"><</span>h2<span class="token punctuation">></span></span><span class="token plain-text">Tag 标签</span><span class="token tag"><span class="token punctuation"></</span>h2<span class="token punctuation">></span></span>
<span class="token tag"><span class="token punctuation"></</span>div<span class="token punctuation">></span></span>
<span class="token tag"><span class="token punctuation"><</span>div <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span>”bm_c”</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token punctuation"><</span>input <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation">=</span>”text”</span> <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation">=</span>”tags”</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation">=</span>”tags”</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span>”px”</span> <span class="token attr-name">maxlength</span><span class="token attr-value"><span class="token punctuation">=</span>”120″</span> <span class="token attr-name">size</span><span class="token attr-value"><span class="token punctuation">=</span>”80″</span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation">=</span>”$article[tags]”</span> <span class="token punctuation">></span></span>
<span class="token tag"><span class="token punctuation"></</span>div<span class="token punctuation">></span></span><span class="token plain-text">
<div class=”bm_h cl”>
多个Tag 用空格隔开,比如:a b c d ,尾部不需任何符号
</span><span class="token tag"><span class="token punctuation"></</span>div<span class="token punctuation">></span></span>
<span class="token tag"><span class="token punctuation"></</span>div<span class="token punctuation">></span></span>

2、接下来是添加pre_portal_article_title表字段[注意:1、操作前备份数据库,2、不论表前缀是不是默认的,都可以直接用此代码(我的表前缀不是默认的已经成功),如果没有升级成功,那就请用pre_portal_article_title

字段名为:tags ,类型varchar(255), 默认为空。

在网站后台的站长->数据库->升级 下面的Discuz! 数据库升级,文本框,复制下面

alter table pre_portal_article_title add tags varchar(255)

3、修改文章添加,修改,处理,函数/source/include/portalcp/portalcp_article.php(关系到字段入库,重要!)

查找以下代码$_POST[‘pagetitle’] = censor($_POST[‘pagetitle’]);

在该代码下面添加$_POST[‘tags’] = censor(trim($_POST[‘tags’]);

查找以下代码

 

‘author’ <span class="token operator">=</span><span class="token operator">></span> <span class="token variable">$_GET</span><span class="token punctuation">[</span>‘author’<span class="token punctuation">]</span><span class="token punctuation">,</span>
‘from’ <span class="token operator">=</span><span class="token operator">></span> <span class="token variable">$_GET</span><span class="token punctuation">[</span>‘from’<span class="token punctuation">]</span><span class="token punctuation">,</span>
‘fromurl’ <span class="token operator">=</span><span class="token operator">></span> <span class="token variable">$_GET</span><span class="token punctuation">[</span>‘fromurl’<span class="token punctuation">]</span><span class="token punctuation">,</span>
‘dateline’ <span class="token operator">=</span><span class="token operator">></span> <span class="token function">intval</span><span class="token punctuation">(</span><span class="token variable">$_GET</span><span class="token punctuation">[</span>‘dateline’<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
‘url’ <span class="token operator">=</span><span class="token operator">></span> <span class="token variable">$_GET</span><span class="token punctuation">[</span>‘url’<span class="token punctuation">]</span><span class="token punctuation">,</span>

 

‘author’ <span class="token operator">=</span><span class="token operator">></span> <span class="token variable">$_G</span><span class="token punctuation">[</span>‘gp_author’<span class="token punctuation">]</span><span class="token punctuation">,</span>
‘from’ <span class="token operator">=</span><span class="token operator">></span> <span class="token variable">$_G</span><span class="token punctuation">[</span>‘gp_from’<span class="token punctuation">]</span><span class="token punctuation">,</span>
‘fromurl’ <span class="token operator">=</span><span class="token operator">></span> <span class="token variable">$_G</span><span class="token punctuation">[</span>‘gp_fromurl’<span class="token punctuation">]</span><span class="token punctuation">,</span>
‘dateline’ <span class="token operator">=</span><span class="token operator">></span> <span class="token function">intval</span><span class="token punctuation">(</span><span class="token variable">$_G</span><span class="token punctuation">[</span>‘gp_dateline’<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
‘url’ <span class="token operator">=</span><span class="token operator">></span> <span class="token variable">$_G</span><span class="token punctuation">[</span>‘gp_url’<span class="token punctuation">]</span><span class="token punctuation">,</span>
‘tags’ <span class="token operator">=</span><span class="token operator">></span> <span class="token variable">$_POST</span><span class="token punctuation">[</span>‘tags’<span class="token punctuation">]</span><span class="token punctuation">,</span>

4、修改文章显示函数/source/module/portal/portal_view.php

找到代码

 

<span class="token keyword">include_once</span> <span class="token function">template</span><span class="token punctuation">(</span>“diy<span class="token punctuation">:</span>portal<span class="token operator">/</span>view<span class="token punctuation">:</span><span class="token punctuation">{</span><span class="token variable">$catid</span><span class="token punctuation">}</span>”<span class="token punctuation">,</span> <span class="token constant">NULL</span><span class="token punctuation">,</span> <span class="token variable">$tpldirectory</span><span class="token punctuation">,</span> <span class="token constant">NULL</span><span class="token punctuation">,</span> <span class="token variable">$articleprimaltplname</span><span class="token punctuation">)</span><span class="token punctuation">;</span>```

在此代码上一行插入以下代码

$tags=explode(” “,$article[“tags”]);foreach($tags as $val) {
$htmltags .= “<a href=\”/search.php?mod=portal&srchtxt=”.$val.”&searchsubmit=yes\” target=\”_blank\”>”.$val.”</a> “;
}

 

<span class="token number">5</span>、修改文章显示模版`<span class="token operator">/</span><span class="token keyword">template</span><span class="token operator">/</span><span class="token keyword">default</span><span class="token operator">/</span>portal<span class="token operator">/</span>view<span class="token punctuation">.</span>htm`

可以自己选择要放的位置<span class="token punctuation">,</span>例如放到内容下面:查找

`$content<span class="token punctuation">[</span>content<span class="token punctuation">]</span>`

然后在下面加入代码

<div>
<b>Tab标签:</b> $htmltags
</div>

 

进入后台<span class="token punctuation">-></span>工具<span class="token punctuation">-></span>更新缓存。只选择清理数据就可以了。
订阅评论
提醒
guest的头像

0 评论
内联反馈
查看所有评论
0
希望看到您的想法,请您发表评论x