首先解釋下文檔關(guān)鍵詞維護(hù)中這個(gè)“頻率”的意思。我們知道,織夢(mèng)默認(rèn)設(shè)置為30,很多朋友都將其看作是錨文本的鏈接數(shù)量。其實(shí)不然,這個(gè)頻率只是表示關(guān)鍵詞的熱度,同動(dòng)易系統(tǒng)的關(guān)鍵詞權(quán)重等同。只是,織夢(mèng)在這個(gè)地方處理的不好。所以,筆者建議最好不要改動(dòng)。
那么到底應(yīng)該如何控制文檔錨文本鏈接數(shù)量呢?系統(tǒng) 》系統(tǒng)基本參數(shù) 》其他選項(xiàng) 的最后一行。文檔內(nèi)容同一關(guān)鍵詞替換次數(shù)(0為全部替換):1(1表示只鏈接第一個(gè)出現(xiàn)的目標(biāo)關(guān)鍵詞)。如圖:
說(shuō)到這里,可能又會(huì)出現(xiàn)一個(gè)問(wèn)題。比如我在后臺(tái)設(shè)置了兩個(gè)錨文本鏈接“SEO博客”、“SEO”,但文章第一次出現(xiàn)“SEO博客”這個(gè)詞的時(shí)候,本來(lái)設(shè)想是應(yīng)該鏈接到“SEO博客”所對(duì)應(yīng)的頁(yè)面,但是織夢(mèng)默認(rèn)設(shè)置為鏈接到“SEO”所對(duì)應(yīng)的頁(yè)面。那么,這種情況應(yīng)該如何處理呢?
解決方法(先備份)
第一步:打開(kāi)目錄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();
//暫時(shí)屏蔽超鏈接
$body = preg_replace("/(<a(.*))(>)(.*)(<)(\/a>)/isU", '\\1-]-\\4-[-\\6', $body);
global $dsql;
$query="SELECT * FROM dede_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[] = "<u><a href="$key_url" target="_blank">$key</a></u>";
}
foreach ($karr as $key => $word)
{
$body = preg_replace("/(^|>)([^<]+)(?=<|$)/sUe", "_highlight('\\2', \$karr[$key], \$kaarr[$key], '\\1')", $body);
//echo $body."
";
//恢復(fù)超鏈接
$body = preg_replace("/(<a(.*))-\]-(.*)-\[-(\/a>)/isU", '\\1>\\3<\\4', $body);
//暫時(shí)屏蔽超鏈接
$body = preg_replace("/(<a(.*))(>)(.*)(<)(\/a>)/isU", '\\1-]-\\4-[-\\6', $body);
}
//恢復(fù)超鏈接
$body = preg_replace("/(<a(.*))-\]-(.*)-\[-(\/a>)/isU", '\\1>\\3<\\4', $body);
return $body;
}
}//End Archives
//高亮專用, 替換多次是可能不能達(dá)到最多次
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;
}
進(jìn)入后臺(tái)生成,至此大功告成。