子比主题美化

标签美化

标签美化
.article-tags {
margin-bottom: 10px;
}
.article-tags a {
padding: 4px 10px;
background-color: #E6F2FF;
color: white;
font-size: 12px;
line-height: 16px;
font-weight: 400;
margin: 0 5px 5px 0;
border-radius: 2px;
display: inline-block;
transition: transform 0.3s ease;
}
.article-tags a:nth-child(5n) {
background-color: #F2F2F2;
color: #333333;
}
.article-tags a:nth-child(5n+1) {
background-color: #FFCCCC;
color: #800000;
}
.article-tags a:nth-child(5n+2) {
background-color: #FFE5CC;
color: #804D00;
}
.article-tags a:nth-child(5n+3) {
background-color: #CCFFCC;
color: #008000;
}
.article-tags a:nth-child(5n+4) {
background-color: #E6F2FF;
color: #003366;
}
.article-tags a:nth-child(10n+5) {
background-color: #FFF0F5;
color: #800080;
}
.article-tags a:nth-child(10n+6) {
background-color: #FFFACD;
color: #806600;
}
.article-tags a:nth-child(10n+7) {
background-color: #D8BFD8;
color: #800080;
}
.article-tags a:nth-child(10n+8) {
background-color: #E0FFFF;
color: #004d4d;
}
.article-tags a:nth-child(10n+9) {
background-color: #FFD700;
color: #663300;
}
.article-tags a:nth-child(10n+10) {
background-color: #FFC0CB;
color: #330033;
}
.article-tags a:nth-child(10n+11) {
background-color: #FF0000;
color: #800000;
}
.article-tags a:nth-child(10n+12) {
background-color: #008000;
color: #CCFFCC;
}
.article-tags a:nth-child(10n+13) {
background-color: #000080;
color: #CCCCFF;
}
.article-tags a:nth-child(10n+14) {
background-color: #00FF00;
color: #003300;
}
.article-tags a:nth-child(10n+15) {
background-color: #0000FF;
color: #000033;
}
.article-tags a:nth-child(10n+16) {
background-color: #800080;
color: #FFC0CB;
}
.article-tags a:nth-child(10n+17) {
background-color: #FFA500;
color: #663300;
}
.article-tags a:nth-child(10n+18) {
background-color: #FF00FF;
color: #330033;
}
.article-tags a:nth-child(10n+19) {
background-color: #800000;
color: #FFCCCC;
}
.article-tags a:nth-child(10n+20) {
background-color: #008000;
color: #CCFFCC;
}
.article-tags a:hover {
transform: scale(1.1);
}
未登录图片模糊
//未登录文章详情页内图片模糊
function unlogin_css(){
  echo '<style>
  .article-content img {
  -webkit-filter: blur(10px)!important;
    -moz-filter: blur(10px)!important;
    -ms-filter: blur(10px)!important;
    filter: blur(6px)!important;}
  .swiper-close img {
  -webkit-filter: blur(10px)!important;
    -moz-filter: blur(10px)!important;
    -ms-filter: blur(10px)!important;
    filter: blur(6px)!important;}
    </style>';
}
if( !is_user_logged_in()) {add_action( 'wp_head', 'unlogin_css' );};
//未登录全站图片模糊
function all_css(){
  echo '<style>
  img {
  -webkit-filter: blur(10px)!important;
    -moz-filter: blur(10px)!important;
    -ms-filter: blur(10px)!important;
    filter: blur(6px)!important;}
    </style>';
}
if( !is_user_logged_in()) {add_action( 'wp_head', 'all_css' );};
标签加TAG标签链接
//WordPress 自动为文章标签加TAG标签链接
/* 自动为文章内的标签添加内链开始 */

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){
  $posttags = get_the_tags();
  $match_num_from = 2;  // 一个标签在文章中出现少于多少次不添加链接
  $match_num_to = 1; // 一篇文章中同一个标签添加几次链接

  if ($posttags) {
      usort($posttags, "tag_sort");
      foreach($posttags as $tag) {
          $link = get_tag_link($tag->term_id);
          $keyword = $tag->name;
          $cleankeyword = stripslashes($keyword);
          $url = '<a href="' . $link . '" title="' . str_replace('%s', addcslashes($cleankeyword, '()'), __('【查看含有[%s]标签的文章】')) . '"';
          $url .= ' target="_blank">';
          $url .= addcslashes($cleankeyword, '()') . '</a>';
          $limit = rand($match_num_from,$match_num_to);
          $pattern = "/<code.*?>(.*?)<\/code>/is";
          $content = preg_replace_callback(
              $pattern, 
              static function($matches) use ($cleankeyword) {
                  return str_replace($cleankeyword, '%&&&&&%', $matches[0]);
              }, 
              $content
          );
          $title_pattern = "/<(h[1-6]).*?>(.*?)<\/\\1>/is";
          $content = preg_replace_callback(
              $title_pattern, 
              static function($matches) use ($cleankeyword) {
                  return str_replace($cleankeyword, '%&&&&&%', $matches[0]);
              }, 
              $content
          );
          $cleankeyword = preg_quote($cleankeyword,'\'');
          $case = ''; // 添加 $case 变量并初始化为空字符串
          $regEx = '\'(?!((<.*?)|(<a.*?)))('. $cleankeyword . ')(?!(([^<>]*?)>)|([^>]*?</a>))\'s' . $case;
          $content = preg_replace($regEx,$url,$content,$limit);
          $content = str_replace( '%&&&&&%', stripslashes($cleankeyword), $content);
      }
  }
  return $content;
}

add_filter('the_content','tag_link',1);

/* 自动为文章内的标签添加内链结束 */
© 版权声明
THE END
点赞5 分享
评论 抢沙发
头像
请勿发送纯数字、表情等评论
提交
头像

昵称

取消
昵称表情代码图片

    暂无评论内容