dev其他其他功能性代码
小柯Wordpress
1. tag标签内链
自动为文章添加tag标签内链,将代码放入主题functions.php文件内
$match_num_from = 1; $match_num_to = 1; function tag_sort($a, $b){ if ( $a->name == $b->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(); 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'.$case, '$1$2$4$5', $content); $cleankeyword = preg_quote($cleankeyword,'\''); $regEx = '\'(?!((<.*?)|(]*?)>)|([^>]*?))\'s' . $case; $content = preg_replace($regEx,$url,$content,$limit); $content = str_replace( '', stripslashes($ex_word), $content); } } return $content; } add_filter('the_content','tag_link',1);
|
(更多内容已复制)