dedecms关键词內连维护默认是需要和发布文章时匹配通过keyword中设置的关键字作为条件替换来完成的,今天分享的是不通过keyword中设置的关键字作为条件替换,而是在数据库中所有的词中索引匹配的
织梦仿站方法:
测试环境为:DEDECMS v5.7
第一步:/include/arc.archives.class.php(DEDE v5.7)
if($arr['type']=='htmltext' && $GLOBALS['cfg_keyword_replace']=='Y' && !empty($this->Fields['keywords']))
改为:if($arr['type']=='htmltext' && $GLOBALS['cfg_keyword_replace']=='Y')
第二步:/include/arc.archives.class.php(DEDE v5.7)中的 ReplaceKeyword 方法改成:
function ReplaceKeyword($kw,&$body)
{
global $cfg_cmspath;
$maxkey = 3;
$kws = explode(",",trim($kw)); //以分好为间隔符
$i=0;
$karr = $kaarr = $GLOBALS['replaced'] = array();
//暂时屏蔽超链接
$body = preg_replace("#(<a(.*))(>)(.*)(<)(\/a>)#isU", '\\1-]-\\4-[-\\6', $body);
/*
foreach($kws as $k)
{
$k = trim($k);
if($k!="")
{
if($i > $maxkey)
{
break;
}
$myrow = $this->dsql->GetOne("SELECT * FROM cn_keywords WHERE keyword='$k' AND rpurl<>'' ");
if(is_array($myrow))
{
$karr[] = $k;
$GLOBALS['replaced'][$k] = 0;
$kaarr[] = "<a href='{$myrow['rpurl']}'><u>$k</u></a>";
}
$i++;
}
}
*/
$query = "SELECT * FROM cn_keywords WHERE rpurl<>'' ORDER BY rank DESC";
$this->dsql->SetQuery($query);
$this->dsql->Execute();
$j = 0;
while($row = $this->dsql->GetArray())
{
$action = 1;
if($j >= $maxkey) break;
$key = trim($row['keyword']);