早在EMLOG PRO-文章自定義關鍵詞內外鏈插件時發布一個類似的插件,但是慢慢覺得的對通過插件實現的功能最好還是直接集成在模板里那樣才更高效、簡潔。因為以前的標簽內外鏈需要手動去添加操作,現在確實手動操作添加一些關鍵詞太麻煩,于是用以下方法去替代。
實現步驟
1.在需要添加的主題模板中找到module.php添加以下代碼,可以根據具體情況添加多個重復的標簽內鏈
function tag_link($content){ global $CACHE; $match_num_from = 1; //一個標簽少于幾次不鏈接 $match_num_to = 2; //一個標簽最多鏈接幾次 $tag_cache = $CACHE->readCache('tags'); foreach($tag_cache as $value){ $tag_url = Url::tag($value['tagurl']); $keyword = $value['tagname']; $cleankeyword = stripslashes($keyword); $url = "<a style=\"color: inherit;font-weight: inherit !important;text-decoration: none !important;border-bottom: 1px dashed rgb(14, 31, 218);\" href=\"{$tag_url}\" title=\"【查看含有[{$cleankeyword}]標簽的文章】\" target=\"_blank\" >{$cleankeyword}</a>"; $regEx = '\'(?!((<.*?)|(<a.*?)))('. $cleankeyword . ')(?!(([^<>]*?)>)|([^>]*?</a>))\'s'; $tagbq= rand($match_num_from,$match_num_to); $content = preg_replace($regEx,$url,$content,$tagbq); } return $content; }
2.其次在echo_log.php中將文章內容輸出掛載點 <?php echo $log_content; ?> 修改成 <?php echo tag_link($log_content); ?> 即可
? 版權聲明
文章版權歸作者所有,未經允許請勿轉載。
相關文章
暫無評論...