如上图:
emlog官网发布过标签关键词内容,但是标签内外链需要手动挨个去添加,比较繁琐,下面这个方法可以直接替代关键词内外链插件。
Ps:标签关键词内外链有利于网站SEO优化
操作方法:
在主题模板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;
}
然后找到echo_log.php文件修改挂载点,把
<?php echo $log_content; ?>
修改成
<?php echo tag_link($log_content); ?>
评论一下?