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']);
*