本文教大家:dedecms文档关键词维护之关键词出现多次,只给出现的第一个加链接的
举例:当文章中出现了一百次台历时,按官方的原理,他会给一百个台历都加上链接的。dedecms这如何是好?
解决方法(记得先备份)
一、打开目录include中的arc.archivew.class.PHP
找到function ReplaceKeyword($kw,$body)代码,在最下面。然后一直到最下面。替换以下的代码
function ReplaceKeyword($kw,$body) { global $cfg_cmspath; $maxkey = 5; $kws = explode(",",trim($kw)); //以分好为间隔符 $i=0; $karr = $kaarr = $GLOBALS['replaced'] = array(); //暂时屏蔽超链接 $body = preg_replace("/()(.*)(<)(/a>)/isU", '\1-]-\4-[-\6', $body); global $dsql; $query="SELECT * FROM zmb_keywords WHERE rpurl<>'' and sta=1 ORDER BY length(keyword)desc"; $dsql->SetQuery($query); $dsql->Execute(); while($row = $dsql->GetArray()) { $key = trim($row['keyword']); $key_url=trim($row['rpurl']); $karr[] = $key; $kaarr[] = "$key"; } foreach ($karr as $key => $word) { $body = preg_replace("/(^|>)([^<]+)(?=<|$)/sUe","_highlight('\2', $karr[$key], $kaarr[$key], '\1')", $body); //echo $body." "; //恢复超链接 $body = preg_replace("/()/isU",'\1>\3<\4', $body); //暂时屏蔽超链接 $body = preg_replace("/()(.*)(<)(/a>)/isU", '\1-]-\4-[-\6', $body); } //恢复超链接 $body = preg_replace("/()/isU",'\1>\3<\4', $body); return $body; } }//End Archives //高亮专用, 替换多次是可能不能达到最多次 function _highlight($string, $words, $result, $pre) { global $cfg_replace_num; $string = str_replace('"', '"', $string); if($GLOBALS['replaced'][$words] == 1) { return $pre.$string; } if($cfg_replace_num > 0) { $string = preg_replace("/".preg_quote($words)."/", $result, $string, $cfg_replace_num); if(strpos($string, $words) !== false) { $GLOBALS['replaced'][$words] = 1; //echo $words; } } else { $string = str_replace($words, $result, $string); } return $pre.$string; }
二、进入DEDE后台,系统-系统基本参数-其他选项的最后一行。文档内容同一关键词替换次数(0为全部替换),修改为1。
三、进入文档关键词维护,维护需要加入链接的关键词和链接即可。重新生成,效果就出来了。