織夢(mèng)關(guān)鍵詞維護(hù)里面字?jǐn)?shù)多的詞優(yōu)先字?jǐn)?shù)少的詞自動(dòng)內(nèi)鏈
時(shí)間: 2018-11-29 13:54
閱讀: 次
作者:素材無憂網(wǎng)
織夢(mèng)后臺(tái)的關(guān)鍵詞維護(hù)默認(rèn)的情況是字?jǐn)?shù)少的詞優(yōu)先于字?jǐn)?shù)多的詞,比如我們有兩個(gè)這樣的詞:創(chuàng)業(yè)、創(chuàng)業(yè)方向,第二個(gè)詞包含了第一個(gè)詞,在文章中如果出現(xiàn)“創(chuàng)業(yè)方向”這個(gè)詞,默認(rèn)情況下只會(huì)給創(chuàng)業(yè)兩個(gè)字添加關(guān)鍵詞超鏈接,而不是整個(gè)詞,那么我們?cè)趺礃硬拍軐?shí)現(xiàn)字?jǐn)?shù)多的詞優(yōu)先于字?jǐn)?shù)少的詞呢?織夢(mèng)97告訴大家具體的解決方法:
我們找到并打開/include/arc.archives.class.php文件,在里面找到如下代碼:
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); /* foreach($kws as $k) { $k = trim($k); if($k!="") { if($i > $maxkey) { break; } $myrow = $this->dsql->GetOne("SELECT * FROM dede_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 dede_keywords WHERE rpurl<>'' ORDER BY rank DESC"; $this->dsql->SetQuery($query); $this->dsql->Execute(); while($row = $this->dsql->GetArray()) { $key = trim($row['keyword']); $key_url=trim($row['rpurl']); $karr[] = $key; $kaarr[] = "<a href='$key_url' target='_blank'><u>$key</u></a>"; } // 這里可能會(huì)有錯(cuò)誤 六久閣http://www.lol9.cn $body = @preg_replace("#(^|>)([^<]+)(?=<|$)#sUe", "_highlight('2', $karr, $kaarr, '1')", $body); //恢復(fù)超鏈接 $body = preg_replace("#(<a(.*))-]-(.*)-[-(/a>)#isU", '1>3<4', $body); return $body; }
找到后將其替換為如下代碼:
function ReplaceKeyword($kw,&$body) { global $cfg_cmspath,$dsql; $maxkey = 5; $kws = explode(",",trim($kw)); //以分好為間隔符 $i=0; $karr = $kaarr = $GLOBALS['replaced'] = array(); //暫時(shí)屏蔽超鏈接 $body = preg_replace("/(<a(.*))(>)(.*)(<)(/a>)/isU", '1-]-4-[-6', $body); $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."<br/>"; //恢復(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; } } else{$string = str_replace($words, $result, $string); } return $pre.$string; }
替換完成后保存即可,然后重新生成整站
標(biāo)簽: