花魁直播高品质美女在线视频互动社区 - 花魁直播官方版

 歡迎來(lái)到素材無(wú)憂網(wǎng),按 + 收藏我們
登錄 注冊(cè) 退出 找回密碼

dedecms關(guān)鍵詞維護(hù)里面字?jǐn)?shù)多的詞優(yōu)先字?jǐn)?shù)少的詞的解決辦法

時(shí)間: 2018-12-06 11:51 閱讀: 作者:素材無(wú)憂網(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ù)少的詞呢?下面就告訴大家具體的解決方法:


我們找到并打開(kāi)/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 #【分隔符】@__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 #【分隔符】@__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ò)誤
        $body = @preg_replace("#(^|>)([^<]+)(?=<|$)#sUe", "_highlight('\\2', \$karr, \$kaarr, '\\1')", $body);

        //恢復(fù)超鏈接
        $body = preg_replace("#(<a(.*))-\]-(.*)-\[-(\/a>)#isU", '\\1>\\3<\\4', $body);
        return $body;
    }

注意查找代碼的時(shí)候先手動(dòng)去掉代碼里面的【分隔符】字樣!

找到后將其替換為如下代碼:

    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 #【分隔符】@__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;
}

注意手動(dòng)去掉代碼里面的【分隔符】字樣!

 


替換完成后保存即可,然后生成一下文章內(nèi)容試試。

版權(quán)聲明: 本站資源均來(lái)自互聯(lián)網(wǎng)或會(huì)員發(fā)布,如果侵犯了您的權(quán)益請(qǐng)與我們聯(lián)系,我們將在24小時(shí)內(nèi)刪除!謝謝!

轉(zhuǎn)載請(qǐng)注明: dedecms關(guān)鍵詞維護(hù)里面字?jǐn)?shù)多的詞優(yōu)先字?jǐn)?shù)少的詞的解決辦法

標(biāo)簽:  
相關(guān)文章
模板推薦