1、找到 module\sell\admin\template\edit.tpl.php
在 47行处加上
<tr>
<td class="tl"><span class="f_hid">*</span> 关键词(Tag)</td>
<td><input name="post[tag]" type="text" size="60" value="<?php echo $tag;?>"/><?php tips('多个关键词请用空格隔开');?></td>
</tr>
这样总后台就有了,如图:
2、找到 module\sell\admin\index.inc.php
27行 找到 “标题 ” 替换 , '标题', '关键词'
28行 找到 “, 'title',” 替换 , 'title', 'tag',
3、打开 module\sell\sell.class.php
187行 直接替换
$keyword = $item['title'].','.$TYPE[$item['typeid']].','.($item['tag'] ? str_replace(' ', ',', trim($item['tag'])).',' : '').strip_tags(cat_pos(get_cat($item['catid']), ','));
4、打开 module\sell\show.htm.php
28行 加入
- $keytags = $tag ? explode(' ', $tag) : array();
5、打开 module\sell\show.inc.php
36行 加入
- $keytags = $tag ? explode(' ', $tag) : array();
6、打开api\extend.func.php
搜索:
- ?>
- //S 自动生成tag
function substring($str, $lenth, $start=0)
{
$len = strlen($str);
$r = array();
$n = 0;
$m = 0;
for($i=0;$i<$len;$i++){
$x = substr($str, $i, 1);
$a = base_convert(ord($x), 10, 2);
$a = substr( '00000000 '.$a, -8);
if ($n < $start){
if (substr($a, 0, 1) == 0) {
}
else if (substr($a, 0, 3) == 110) {
$i += 1;
}
else if (substr($a, 0, 4) == 1110) {
$i += 2;
}
$n++;
}
else{
if (substr($a, 0, 1) == 0) {
$r[] = substr($str, $i, 1);
}else if (substr($a, 0, 3) == 110) {
$r[] = substr($str, $i, 2);
$i += 1;
}else if (substr($a, 0, 4) == 1110) {
$r[] = substr($str, $i, 3);
$i += 2;
}else{
$r[] = ' ';
}
if (++$m >= $lenth){
break;
}
}
}
return join('',$r);
}
function convert_encoding($str,$nfate,$ofate){
if ($ofate=="UTF-8"){ return $str; }
if ($ofate=="GB2312"){ $ofate="GBK"; }
if(function_exists("mb_convert_encoding")){
$str=mb_convert_encoding($str,$nfate,$ofate);
}
else{
$ofate.="//IGNORE";
$str=iconv( $nfate , $ofate ,$str);
}
return $str;
}
function getpage($url,$charset)
{
$charset = strtoupper($charset);
$content = "";
if(!empty($url)) {
if( function_exists('curl_init') ){
$ch = @curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; )');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_cookie, 'domain=www.baidu.com');
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$content = @curl_exec($ch);
curl_close($ch);
}
else if( ini_get('allow_url_fopen')==1 ){
$content = @file_get_contents($url);
}
else{
die('当前环境不支持采集【curl 或 allow_url_fopen】,请检查php.ini配置;');
}
$content = convert_encoding($content,"utf-8",$charset);
}
return $content;
}
function gettag($title,$content){
$data = getpage('https://keyword.discuz.com/related_kw.html?ics=utf-8&ocs=utf-8&title='.rawurlencode($title).'&content='.rawurlencode(substring($content,500)),'utf-8');
if($data) {
$parser = xml_parser_create();
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
xml_parse_into_struct($parser, $data, $values, $index);
xml_parser_free($parser);
$kws = array();
foreach($values as $valuearray) {
if($valuearray['tag'] == 'kw') {
if(strlen($valuearray['value']) > 3){
$kws[] = trim($valuearray['value']);
}
}elseif($valuearray['tag'] == 'ekw'){
$kws[] = trim($valuearray['value']);
}
}
return implode(' ',$kws);
}
return false;
}
//E 自动生成tag
7、打开module\sell\sell.class.php
搜索:
- if($this->itemid) {
- //S 自动生成tag
if($post['tag']=='' && $post['uptag']==1) $post['tag'] = gettag($post['title'],$post['content']);
//E 自动生成tag
- $update = '';
- //S 自动生成tag
$tag = gettag($item['title'],$item['content']);
if($item['tag'] == '') {
$update .= ",tag='$tag'";
}
//E 自动生成tag
搜索:
- <?php tips('多个关键词请用空格隔开');?>
- <input type="checkbox" name="post[uptag]" value="1" checked>自动生成
9、前端会员中心:如默认路径 \template\default\member\my_sell.htm
找到:70行,在下面加上
- <tr title="提示:多个关键词请用空格分隔">
<td class="tl">关键词(Tag)</td>
<td class="tr f_gray"><input name="post[tag]" type="text" size="60" value="{$tag}"/> <input type="checkbox" name="post[uptag]" value="1" checked>自动生成 (提示:多个关键词请用空格隔开);</td>
</tr>
如图:
效果:
前台标签调用:
列表, (列表用记得在 “列表或搜索主字段” 加上 ,tag)
- {if $t[tag]} 标签:
{php $tag = str_replace(',', ' ', $t[tag]);}
{php $sell_tags = explode(' ', $t[tag]);}
{loop $sell_tags $v} <a href="{$MOD[linkurl]}{rewrite('search.php?kw='.urlencode($v))}">{$v}</a>{/loop}
{/if}
内容页 :
- {if $tag}关 键 词:{php $tag = str_replace(',', ' ', $tag);}
{php $sell_tags = explode(' ', $tag);}
{loop $sell_tags $v} <a href="{$MOD[linkurl]}{rewrite('search.php?kw='.urlencode($v))}">{$v}</a>{/loop}
{/if}
最终效果