泥耶论坛 发表于 2025-10-6 12:38:27

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

早在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); ?> 即可
页: [1]
查看完整版本: Emlog文章内容自动添加标签链接