陈奇网络工作室

让织梦自动内链长尾词优先添加的方法

织梦系统是个很适合seo优化的cms系统,系统自带了自动内链工具,可以很方便的增加文章内链,但是在使用过程中我发现短词经常会优先加链接,造成长尾词无法加到内链的情况,为了让体验感更好,我们需要调整织梦的系统文件,让长尾词优先短词添加内链。

具体方法如下:

1:首先在include目录中找到arc.archivew.class.php这个文件。

2:查找:

function ReplaceKeyword($kw,&$body)

将这段代码至文件结束部分替换为下方内容(注意:你需要确认自己的cms系统没进行过二次改动)

function ReplaceKeyword($kw,&$body)  
    {  
       global $cfg_cmspath;  
       $maxkey = 5;  
       $kws = explode(",",trim($kw)); //以分好为间隔符  
       $i=0;  
       $karr = $kaarr = $GLOBALS['replaced'] = array();  
       //暂时屏蔽超链接  
       $body = preg_replace("/(<a(.*))(>)(.*)(<)(\/a>)/isU", '\\1-]-\\4-[-\\6', $body);  
       global $dsql;  
       $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[] = "<a href='$key_url' rel='bookmark' target='_blank'>$key</a>";  
       }  
       foreach ($karr as $key => $word)  
       {  
        $body = preg_replace("/(^|>)([^<]+)(?=<|$)/sUe", "_highlight('\\2', \$karr[$key], \$kaarr[$key], '\\1')", $body);  
    //echo $body."";  
    //恢复超链接  
        $body = preg_replace("/(<a(.*))-\]-(.*)-\[-(\/a>)/isU", '\\1>\\3<\\4', $body);  
    //暂时屏蔽超链接  
        $body = preg_replace("/(<a(.*))(>)(.*)(<)(\/a>)/isU", '\\1-]-\\4-[-\\6', $body);  
       }  
       //恢复超链接  
       $body = preg_replace("/(<a(.*))-\]-(.*)-\[-(\/a>)/isU", '\\1>\\3<\\4', $body);  
       return $body;  
    }  
    }//End Archives   
    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;  
    }

 

赞 ()
分享到:更多 ()

相关推荐

后台-系统设置-扩展变量-手机广告位-内容页底部广告位3
留言与评论(共有 0 条评论)
   
验证码: