如今不論是大型的網(wǎng)站還是個(gè)人博客,在乎的不是外鏈接多少?zèng)Q定網(wǎng)站的權(quán)重,而是本身網(wǎng)站的內(nèi)容質(zhì)量和內(nèi)鏈接的建設(shè),讓用戶/搜索引擎輕易的找到我們需要的相關(guān)內(nèi)容。內(nèi)容之間的內(nèi)鏈建設(shè)還是比較重要的,我們可能有些用戶喜歡手工制造,當(dāng)然這樣很好,如果我們比較怕麻煩,可以通過(guò)與WORDPRESS設(shè)定的TAG關(guān)聯(lián)作為內(nèi)鏈效果。
一般都可以使用插件實(shí)現(xiàn),老蔣一貫比較喜歡使用無(wú)插件效果,所以整理到這個(gè)無(wú)插件實(shí)現(xiàn)TAG內(nèi)鏈效果。
//連接數(shù)量
$match_num_from = 1; //一個(gè)關(guān)鍵字少于多少不替換
$match_num_to = 2; //一個(gè)關(guān)鍵字最多替換
//連接到WordPress的模塊
add_filter('the_content','tag_link',1);
//按長(zhǎng)度排序
function tag_sort($a, $b){
if ( $a->name == $b->name ) return 0;
return ( strlen($a->name) > strlen($b->name) ) ? -1 : 1;
}
//改變標(biāo)簽關(guān)鍵字
function tag_link($content){
global $match_num_from,$match_num_to;
$posttags = get_the_tags();
if ($posttags) {
usort($posttags, "tag_sort");
foreach($posttags as $tag) {
$link = get_tag_link($tag->term_id);
$keyword = $tag->name;
//連接代碼
$cleankeyword = stripslashes($keyword);
$url = "<a href="$link" title="".str_replace('%s',addcslashes($cleankeyword, '$'),__('View all posts in %s')).""";
$url .= ' target="_blank" class="tag_link"';
$url .= ">".addcslashes($cleankeyword, '$')."</a>";
$limit = rand($match_num_from,$match_num_to);
//不連接的 代碼
$content = preg_replace( '|(<a[^>]+>)(.*)('.$ex_word.')(.*)(</a[^>]*>)|U'.$case, '$1$2%&&&&&%$4$5', $content);
$content = preg_replace( '|(<img)(.*?)('.$ex_word.')(.*?)(>)|U'.$case, '$1$2%&&&&&%$4$5', $content);
$cleankeyword = preg_quote($cleankeyword,''');
$regEx = ''(?!((<.*?)|(<a.*?)))('. $cleankeyword . ')(?!(([^<>]*?)>)|([^>]*?</a>))'s' . $case;
$content = preg_replace($regEx,$url,$content,$limit);
$content = str_replace( '%&&&&&%',
stripslashes($ex_word), $content);
}
}
return $content;
}
把上面的代碼腳本,放置到當(dāng)前WODPRESS主題中的FUNCTIONS.PHP文件中,上面對(duì)應(yīng)的描述參數(shù)根據(jù)需要修改。比如老蔣博客中的內(nèi)容TAG內(nèi)鏈就使用的這種方法。
本文來(lái)自老蔣部落:http://www.itbulu.com/wp-in-link.html 轉(zhuǎn)載注明出處。
新聞熱點(diǎn)
疑難解答
圖片精選