最新公告
  • 欢迎您光临牛气网,本站秉承“用心服务,做好服务”致力为站长提供优质的售后服务!立即加入我们
  • 织梦关键词维护里面字数多的词优先字数少的词自动内链

    织梦后台的关键词维护默认的情况是字数少的词优先于字数多的词,比如我们有两个这样的词:创业、创业方向,第二个词包含了第一个词,在文章中如果出现“创业方向”这个词,默认情况下只会给创业两个字添加关键词超链接,而不是整个词,那么我们怎么样才能实现字数多的词优先于字数少的词呢?织梦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(); //暂时屏蔽超链接 $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>"; } // 这里可能会有错误 织梦http://www.niuqi.net $body = @preg_replace("#(^|>)([^<]+)(?=<|$)#sUe", "_highlight('2', $karr, $kaarr, '1')", $body); //恢复超链接 $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(); //暂时屏蔽超链接 $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/>"; //恢复超链接 $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; } } else{$string = str_replace($words, $result, $string); } return $pre.$string; }

    替换完成后保存即可,然后重新生成整站

    1、本站所有资源皆来源于网络和用户自行上传,因此不包括售后和技术,敬请谅解!
    2、本站不保证所提供的源码的准确性、安全性和功能完善性,资源仅用于学习用!
    3、您下载的资源,请务必在24小时内删除,资源仅提供本地测试,请勿商用或者非法用途都与本站无关,一切后果自负!
    4、如发现资源下载不了,或者侵权请及时联系客服或者邮箱admin#niuqi.net,#改为@!
    牛气网 » 织梦关键词维护里面字数多的词优先字数少的词自动内链

    发表评论

    • 72会员总数(位)
    • 4096资源总数(个)
    • 0本周发布(个)
    • 0 今日发布(个)
    • 206稳定运行(天)

    牛气网NIUQI.NET站长源码平台

    开通SVIP会员 了解详情