返回列表 发布新帖
查看: 10|回复: 0

Emlog文章内容自动添加标签链接

1836

主题

52

回帖

1万

积分

管理员

积分
19864
发表于 2025-10-6 12:38:27 | 查看全部 |阅读模式
早在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); ?> 即可

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关灯 在本版发帖
扫一扫添加微信客服
QQ客服返回顶部
快速回复 返回顶部 返回列表