WordPress自动为文章标签添加该标签的链接
发布时间:2020-05-25 00:26:52 所属栏目:CMS系统 来源:互联网
导读:站长朋友们在使用WordPress建站的过程中,当网站中的文章(post)和标签(tag)越来越多时,很多时候就希望给文章中出现的标签(tag)自动添加上该标签的链接。这篇WordPress教程里,我们就向大家介绍一下具体的方法。
|
站长朋友们在使用的过程中,当网站中的文章(post)和标签(tag)越来越多时,很多时候就希望给文章中出现的标签(tag)自动添加上该标签的链接。这篇WordPress教程里,我们就向大家介绍一下具体的方法。 切换到主题目录,打开functions.php文件,加入以下代码: name ) return 0;
return ( strlen($a->name) > strlen($b->name) ) ? -1 : 1;
}
//为符合条件的标签添加链接
function tag_link($content){
global $match_num_from,$match_num_to;
$posttags = get_the_tags();
//$posttags = get_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 = "";
$limit = rand($match_num_from,$match_num_to);
//不链接的代码
$content = preg_replace( '|(]+>)(.*)('.$ex_word.')(.*)(]*>)|U'.$case,'$1$2%&&&&&%$4$5',$content);
$content = preg_replace( '|( | )|U')|([^>]*?))'s'
