您现在的位置是:黎青松SEO博客 >> 织梦CMS教程

织梦关键词自动内链 控制内链数量

黎青松SEO博客150人已围观

简介后台-系统-核心设置-关键字替换【是】后台-系统-其他选项-关键词替换次数【1】或者【0】关键词长短优先级问题比如有“长词”、“我是大长词”、“我是小长词”,同时在一篇文章中出

关键词长短优先级问题

比如有“长词”、“我是大长词”、“我是小长词”,同时在一篇文章中出现,程序会优先使用短的词。

(此图片来源于网络,如有侵权,请联系删除! )

(此图片来源于网络,如有侵权,请联系删除! )

长短优先级问题和PHP5.5以上问题的解决方法

打开 /include/arc.archives.class.php 找到

$query = "SELECT * FROM keywords WHERE rpurl<>'' ORDER BY rank DESC";

改成

$query = "SELECT char_length(keyword) AS num,aid,keyword,rpurl,rank FROM keywords WHERE rpurl<>'' ORDER BY num DESC";

继续找到

"#".preg_quote($word)."#"

改成

"#".preg_quote($word, "#")."(?!<)#"

继续找到

$body = @preg_replace_callback("#(^|>)([^<]+)(?=<|$)#sU", "_highlight('\\2', \$karr, \$kaarr, '\\1')", $body);

改成

global $cfg_replace_num;

if($cfg_replace_num > 0)

{

$query = "SELECT char_length(keyword) AS num,aid,keyword,rpurl,rank FROM keywords WHERE rpurl<>'' ORDER BY num DESC";

$this->dsql->SetQuery($query);

$this->dsql->Execute();

while($row = $this->dsql->GetArray())

{

$key = trim($row['keyword']);

$key_url=trim($row['rpurl']);

$body = str_replace_limit($key, "<a href='$key_url' target='_blank'><u>$key</u></a>", $body, $cfg_replace_num);

}

}

else

{

$query = "SELECT char_length(keyword) AS num,aid,keyword,rpurl,rank FROM keywords WHERE rpurl<>'' ORDER BY num DESC";

$this->dsql->SetQuery($query);

$this->dsql->Execute();

while($row = $this->dsql->GetArray())

{

$key = trim($row['keyword']);

$key_url=trim($row['rpurl']);

$body = str_replace($key, "<a href='$key_url' target='_blank'><u>$key</u></a>", $body);

}

}


继续找到

//高亮专用

在它上面加入

//指定替换次数功能

function str_replace_limit($search, $replace, $subject, $limit)

{

if(is_array($search))

{

foreach($search as $k=>$v)

{

$search[$k] = "#".preg_quote($search[$k], "#")."(?!<)#";

}

}

else

{

$search = "#".preg_quote($search, "#")."(?!<)#";

}

return preg_replace($search, $replace, $subject, $limit);


加入方法2。可控制内链个数。

global $cfg_replace_num, $cfg_limit_key;

            if($cfg_replace_num > 0)

            {

                

                $query = "SELECT char_length(keyword) AS num,aid,keyword,rpurl,rank FROM dede_keywords WHERE rpurl<>'' ORDER BY num DESC";

                $this->dsql->SetQuery($query);

                $this->dsql->Execute();

                $anum = 0;

                while($row = $this->dsql->GetArray())

                {

                    $old_body = $body;

                    if ($anum > $cfg_limit_key) break;

                    $key = trim($row['keyword']);

                    $key_url = trim($row['rpurl']);

                    $body = str_replace_limit($key, "< a href=' ' target='_blank'><u>$key</u></ a>", $body, $cfg_replace_num);

                    if($body != $old_body){

                        $anum++;

                    }


                }

            }

            else

            {

                $query = "SELECT char_length(keyword) AS num,aid,keyword,rpurl,rank FROM dede_keywords WHERE rpurl<>'' ORDER BY num DESC";

                $this->dsql->SetQuery($query);

                $this->dsql->Execute();

                $anum = 0;

                while($row = $this->dsql->GetArray())

                {

                    $old_body = $body;

                    if ($anum > $cfg_limit_key) break;

                    $key = trim($row['keyword']);

                    $key_url=trim($row['rpurl']);

                    $body = str_replace($key, "< a href='$key_url' target='_blank'><u>$key</u></ a>", $body);

                    if($body != $old_body){

                        $anum++;

                    }

                }

            }



完成,最终效果

Tags: 织梦关键词自动内链   织梦关键词自动内链数量  

相关文章

黎青松SEO博客

擅长:企业站优化、行业站数据采集处理

Q Q:191988123

现居:四川-成都

网址:www.alitaohuo.com

标签云

(function(){ var src = (document.location.protocol == "http:") ? "http://js.passport.qihucdn.com/11.0.1.js?1d7dde81dc0903e04d3ac0b9599444f6":"https://jspassport.ssl.qhimg.com/11.0.1.js?1d7dde81dc0903e04d3ac0b9599444f6"; document.write('<\/mip-script>'); })(); (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();