阅读视图

发现新文章,点击刷新页面。

网站使用umami api制作数据挂件

前言

因为51统计最近一直出现问题,并且有传言称51统计的js文件会出现劫持跳转的问题,于是就想更换统计方式,Umami因此成为我的主要选择。

51统计好的地方在于能够显示出统计挂件,但是有大佬用umami的api也制作出了数据挂件。

参考

张洪HEO:https://blog.zhheo.com/p/61e9.html

木木木木木:https://immmmm.com/hi-umami-api/

教程

1.首先搭建属于自己的umami,具体可以访问

2.token可以到搭建好的umami站点,然后打开开发者工具,找到网络中的https://你的域名/api/auth/verify 里的请求头中的authorization 中Bearer 后面的内容

3.网站ID就是后台网站中的比如https://你的域名/websites/0ba3d4b8-95ec-4e33-a727-32b013d6cfa7 ,其中0ba3d4b8-95ec-4e33-a727-32b013d6cfa7就是网站ID

3.更改如下代码,并且添加到WordPress的自定义html中

<div class="tongji">
今日访问人数 <span id="todayUv">0</span> | 今日访问量 <span id="todayPv">0</span> | 本月访问量 <span id="monthPv">0</span> | 总访问量 <span id="totalPv">0</span>
</div>

<script>
  document.addEventListener('DOMContentLoaded', () => {
    umiTongji();
  });

  function umiTongji() {
    var umiToken = "你的token"; //获取到的 token
    var umiId = "网站ID"; //获取到的 websiteId
    var umiTime = Date.parse(new Date());
    var todayStart = new Date().setHours(0, 0, 0, 0);
    var monthStart = new Date(new Date().getFullYear(), new Date().getMonth(), 1).getTime();
    var umiUrl = "https://你的域名/api/websites/" + umiId + "/stats?startAt=" + todayStart + "&endAt=" + umiTime;

    fetch(umiUrl, {
        method: 'GET',
        mode: 'cors',
        cache: 'default',
        headers: {
          'Authorization': 'Bearer ' + umiToken,
          'Content-Type': 'application/json'
        }
      })
      .then(res => res.json())
      .then(resdata => {
        document.querySelector('#todayPv').innerHTML = resdata.pageviews.value;
        document.querySelector('#todayUv').innerHTML = resdata.visitors.value;
      });

    umiUrl = "https://你的域名/api/websites/" + umiId + "/stats?startAt=" + monthStart + "&endAt=" + umiTime;

    fetch(umiUrl, {
        method: 'GET',
        mode: 'cors',
        cache: 'default',
        headers: {
          'Authorization': 'Bearer ' + umiToken,
          'Content-Type': 'application/json'
        }
      })
      .then(res => res.json())
      .then(resdata => {
        document.querySelector('#monthPv').innerHTML = resdata.pageviews.value;
      });

    umiUrl = "https://你的域名/api/websites/" + umiId + "/stats?startAt=0&endAt=" + umiTime;

    fetch(umiUrl, {
        method: 'GET',
        mode: 'cors',
        cache: 'default',
        headers: {
          'Authorization': 'Bearer ' + umiToken,
          'Content-Type': 'application/json'
        }
      })
      .then(res => res.json())
      .then(resdata => {
        document.querySelector('#totalPv').innerHTML = resdata.pageviews.value;
      });
  }
</script>
<style>
  #todayUv, #todayPv, #monthPv, #totalPv {
    color: #00a0ff;
  }
</style>

WordPress文章页侧边栏添加文章目录

前言

不少主题都支持文章页的侧边栏添加文章目录的小工具

教程

将如下代码放到子主题的function.php中

class Article_TOC_Widget extends WP_Widget {

    public function __construct() {
        parent::__construct(
            'article_toc_widget',
            '文章目录小工具',
            array( 'description' => '在文章或页面的侧边栏中显示文章目录' )
        );
    }

    public function widget( $args, $instance ) {
        global $post;
        if ( is_singular() && ! empty( $post->post_content ) ) {
            $toc = $this->get_toc( $post->post_content );
            if ( ! empty( $toc ) ) {
                echo $args['before_widget'];
                echo $args['before_title'] . '文章目录' . $args['after_title'];
                echo '<ul>' . $toc . '</ul>';
                echo $args['after_widget'];
            }
        }
    }

    public function get_toc( $content ) {
        $toc = '';
        $dom = new DOMDocument();
        @$dom->loadHTML( mb_convert_encoding( $content, 'HTML-ENTITIES', 'UTF-8' ) );
        $xpath = new DOMXPath( $dom );
        $headers = $xpath->query( '//h2|//h3|//h4|//h5|//h6' );
        if ( $headers->length > 0 ) {
            foreach ( $headers as $header ) {
                $id = $header->getAttribute( 'id' );
                if ( empty( $id ) ) {
                    $id = sanitize_title( $header->nodeValue );
                    $header->setAttribute( 'id', $id );
                }
                $toc .= '<li><a href="#' . $id . '">' . $header->nodeValue . '</a></li>';
            }
        }
        return $toc;
    }

}
function register_article_toc_widget() {
    register_widget( 'Article_TOC_Widget' );
}
add_action( 'widgets_init', 'register_article_toc_widget' );

结语

功能不是很完善,但是可以显示了,需要其他功能自己添加

WordPress页面添加打赏按钮

前言

虽然WordPress很多主题包括CoreNext在文章的底部都有赞赏的按钮,但是页面中是没有的,为了解决这一问题,所以找到了如下教程。

教程

教程非常简单,在需要添加的页面位置添加如下代码,记得更换其中的二维码地址,当然如果你想赞助我的话也是可以的。

<!-- 打赏 -->
<div id="rewardSection" style="padding: 10px 0; margin: 20px auto; width: 100%; font-size: 16px; text-align: center;"><button id="rewardButton" style="border: 1px solid #ccc; line-height: 36px; text-align: center; height: 36px; display: block; border-radius: 4px; -webkit-transition-duration: 0.4s; transition-duration: 0.4s; background-color: #04be02; color: #ffffff; margin: 0 auto; padding: 0 25px;">¥ 点我显示打赏</button>
<div id="QR" style="display: none;">
<div id="wechat" style="display: inline-block; margin: 20px;"><img id="wechat_qr" style="width: 180px; max-width: 100%; display: inline-block; margin: 0.8em 2em 0 2em;" src="https://www.xrbk.cn/api/img/sk/wx.png" alt="微信二维码" />微信打赏

</div>
<div id="alipay" style="display: inline-block; margin: 20px;"><img id="alipay_qr" style="width: 180px; max-width: 100%; display: inline-block; margin: 0.8em 2em 0 2em;" src="https://www.xrbk.cn/api/img/sk/zfb.png" alt="支付宝二维码" />支付宝打赏

</div>
</div>
</div>
<script>
jQuery(document).ready(function($) {
    $('#rewardButton').click(function() {
        $('#QR').toggle();
    });
});
</script>

<!-- 打赏 -->

 

WordPress添加彩色文本渐变框

前言

CoreNext主题自带的编辑器增强内有标星面板,但是颜色有点少,所以找了个教程给WordPress添加彩色文本渐变框。

教程

1.首先将如下代码添加到CoreNext子主题的function.php 中,如果其他主题也有子主题一样操作。

 add_action('after_wp_tiny_mce', 'bolo_after_wp_tiny_mce');
 function bolo_after_wp_tiny_mce($mce_settings) {
 ?>
 <script type="text/javascript"> 
 QTags.addButton( 'z_mhz', '迷幻紫', '<div id="zm_mhz">迷幻紫</div>n', "" );
 QTags.addButton( 'z_xgh', '西瓜红', '<div id="zm_xgh">西瓜红</div>n', "" );
 QTags.addButton( 'z_tkzj', '天空之境', '<div id="zm_tkzj">天空之境</div>n', "" );
 QTags.addButton( 'z_xyz', '小宇宙', '<div id="zm_xyz">小宇宙</div>n', "" );
 QTags.addButton( 'z_gll', '橄榄绿', '<div id="zm_gll">橄榄绿</div>n', "" );
 QTags.addButton( 'z_xty', '小太阳', '<div id="zm_xty">小太阳</div>n', "" );
 QTags.addButton( 'z_yyz', '优雅紫', '<div id="zm_yyz">优雅紫</div>n', "" );
 QTags.addButton( 'z_szh', '深邃黑', '<div id="zm_szh">深邃黑</div>n', "" );
 QTags.addButton( 'z_wbk', '无边框', '<div id="zm_wbk">无边框</div>n', "" ); 
 function bolo_QTnextpage_arg1() {
 }
 </script>
 <?php
 }

2.将如下CSS代码添加到CoreNext子主题的CSS文件夹中的main.css中

/*渐变框区块*/
#zm_mhz,#zm_xgh,#zm_tkzj,#zm_xyz,#zm_gll ,#zm_xty,#zm_yyz,#zm_szh,#zm_wbk{
  /*圆角值,在此定义*/
  border-radius: 8px;
}
/*迷幻紫*/
#zm_mhz{
    color: #555555;
    overflow: hidden;
    margin: 10px 0;
    padding: 15px 15px 15px 35px;
    /*border-radius: 10px;*/
    box-shadow: 6px 0 12px -5px rgb(190, 196, 252), -6px 0 12px -5px rgb(189, 196, 252);
    background-color: #8EC5FC;
    background-image: linear-gradient(62deg,#8EC5FC 0%,#E0C3FC 100%);
    background-image: -webkit-linear-gradient(62deg,#8EC5FC 0%,#E0C3FC 100%);
}
/*西瓜红*/
#zm_xgh{
      color: #555555;
    overflow: hidden;
    margin: 10px 0;
    padding: 15px 15px 15px 35px;
    /*border-radius: 10px;*/
    box-shadow: 6px 0 12px -5px rgb(255, 176, 172), -6px 0 12px -5px rgb(255, 161, 174);
    background-color: #ff9a8b66;
    background-image: linear-gradient(220deg,#FF9A8B 0%,#ff6a8838 55%,#FF99AC 100%);
    background-image: -webkit-linear-gradient(220deg,#ff9a8b7a 0%,#ff6a88ab 55%,#ff99ac82 100%);
}
/*华为P30 天空之境*/
#zm_tkzj {
    color: #555555;
    overflow: hidden;
    margin: 10px 0;
    padding: 15px 15px 15px 35px;
    /*border-radius: 10px;*/
    box-shadow: 6px 0 12px -5px rgb(253, 223, 234), -6px 0 12px -5px rgb(215, 240, 243);
    background-color: #FFDEE9;
    background-image: linear-gradient(0deg,#ffdee9c4 0%,#b5fffc8f 100%);
    background-image: -webkit-linear-gradient(0deg,#ffdee9c4 0%,#b5fffc8f 100%);
}
/*小宇宙*/
#zm_xyz {
    color: #eeeeee;
    overflow: hidden;
    margin: 10px 0;
    padding: 15px 15px 15px 35px;
    /*border-radius: 10px;*/
    box-shadow: 6px 0 12px -5px rgb(12, 85, 141), -6px 0 12px -5px rgba(10, 58, 93, 0);
    background-image: radial-gradient( circle 263px at 100.2% 3%, rgba(12,85,141,1) 31.1%, rgba(205,181,93,1) 36.4%, rgba(244,102,90,1) 50.9%, rgba(199,206,187,1) 60.7%, rgba(249,140,69,1) 72.5%, rgba(12,73,116,1) 72.6% );
}
/*橄榄绿*/
#zm_gll {
    color: #eeeeee;
    overflow: hidden;
    margin: 10px 0;
    padding: 15px 15px 15px 35px;
    /*border-radius: 10px;*/
    box-shadow: 6px 0 12px -5px rgb(68, 110, 92), -6px 0 12px -5px rgb(204, 212, 163);
    background-image: linear-gradient( 102deg, rgba(68,110,92,1) 17.4%, rgba(107,156,120,1) 49.3%, rgba(154,183,130,1) 83.4%, rgba(247,237,191,1) 110.3% );
}
/*小太阳*/
#zm_xty {
    color: #ffffff;
    overflow: hidden;
    margin: 10px 0;
    padding: 15px 15px 15px 35px;
     /*border-radius: 10px; */
    box-shadow: 6px 0 12px -5px rgb(253, 223, 234), -6px 0 12px -5px rgb(215, 240, 243);
    background-image: radial-gradient( circle farthest-corner at -8.9% 51.2%, rgba(255,124,0,1) 0%, rgba(255,124,0,1) 15.9%, rgba(255,163,77,1) 15.9%, rgba(255,163,77,1) 24.4%, rgba(19,30,37,1) 24.5%, rgba(19,30,37,1) 66% );
}
/*优雅紫*/
#zm_yyz {
  color: #ffffff;
    overflow: hidden;
    margin: 10px 0;
    padding: 15px 15px 15px 35px;
    /*border-radius: 10px;*/
    box-shadow: 6px 0 12px -5px rgb(175, 160, 208), -6px 0 12px -5px rgba(177, 161, 207, 0);
    background-image: radial-gradient( circle farthest-corner at 10% 20%, rgba(95,117,227,1) 0%, rgba(188,167,205,1) 90% );
}
/*深邃黑*/
#zm_szh {
  color: #c7c7c7;
    overflow: hidden;
    margin: 10px 0;
    padding: 15px 15px 15px 35px;
    /*border-radius: 5px;*/
    box-shadow: 6px 0 12px -5px rgb(155, 170, 185), -6px 0 12px -5px rgba(177, 161, 207, 0);
    background-image: radial-gradient( circle farthest-corner at 10% 20%, rgba(0,0,0,1) 0%, rgba(64,64,64,1) 90.2% );
}
/*无边框*/
#zm_wbk {
    color: #000000;
    overflow: hidden;
    margin: 10px 0;
    padding: 15px 15px 15px 35px;
}
#zm_xyz a , #zm_gll a{
   color: #eeeeee;
}
#zm_szh a{
  color: #c7c7c7;  
}
#zm_xty a, #zm_yyz a{
  color: #ffffff;
}

3.现在就可以在编辑器内添加如下代码使用效果了。

<div id="zm_mhz">迷幻紫</div>
<div id="zm_xgh">西瓜红</div>
<div id="zm_tkzj">天空之境</div>
<div id="zm_xyz">小宇宙</div>
<div id="zm_gll">橄榄绿</div>
<div id="zm_xty">小太阳</div>
<div id="zm_yyz">优雅紫</div>
<div id="zm_szh">深邃黑</div>
<div id="zm_wbk">无边框</div>

演示

图片[1]-新锐博客

参考

原文地址:https://www.owwee.cn/post/212.html

WordPress首页文章底部添加线条

前言

在某个网站看到鼠标放到首页文章,它的底部会出现线条,于是就突发奇想想给自己网站弄一个

效果

别人的:

图片[1]-新锐博客

自己的:

图片[2]-新锐博客

教程

请将如下两个代码中的任何一个添加到子主题的CSS文件夹中的main.css 中或在主题设置中添加自定义css代码

1.固定颜色

.post-item {
  position: relative;
}

.post-item::before {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  width: 0;
  height: 3px;
  background: var(--color, #000);
  transition: width 1s, background-color 0.5s; /* 添加了背景颜色的过渡效果 */
}

.post-item:hover::before {
  width: 100%;
}

/* 使用计算来设置颜色 */
.post-item:nth-of-type(1)::before {
  --color: hsl(0, 100%, 50%); /* 设置第一个.post-item的线条颜色 */
}

.post-item:nth-of-type(2)::before {
  --color: hsl(72, 100%, 50%); /* 设置第二个.post-item的线条颜色 */
}

.post-item:nth-of-type(3)::before {
  --color: hsl(144, 100%, 50%); /* 设置第三个.post-item的线条颜色 */
}

.post-item:nth-of-type(4)::before {
  --color: hsl(216, 100%, 50%); /* 设置第四个.post-item的线条颜色 */
}

.post-item:nth-of-type(5)::before {
  --color: hsl(288, 100%, 50%); /* 设置第五个.post-item的线条颜色 */
}

.post-item:nth-of-type(6)::before {
  --color: hsl(324, 100%, 50%); /* 设置第六个.post-item的线条颜色 */
}

.post-item:nth-of-type(7)::before {
  --color: hsl(36, 100%, 50%); /* 设置第七个.post-item的线条颜色 */
}

.post-item:nth-of-type(8)::before {
  --color: hsl(108, 100%, 50%); /* 设置第八个.post-item的线条颜色 */
}

.post-item:nth-of-type(9)::before {
  --color: hsl(180, 100%, 50%); /* 设置第九个.post-item的线条颜色 */
}

.post-item:nth-of-type(10)::before {
  --color: hsl(252, 100%, 50%); /* 设置第十个.post-item的线条颜色 */
}

2.动态颜色

.post-item {
  position: relative;
}

.post-item::before {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  width: 0;
  height: 3px;
  background: var(--color, #000);
  transition: width 1s;
}

.post-item:hover::before {
  width: 100%;
}

.post-item:hover::before {
  animation: randomColor 2s infinite;
}

@keyframes randomColor {
  0% {
    background: red;
  }
  25% {
    background: blue;
  }
  50% {
    background: green;
  }
  75% {
    background: yellow;
  }
  100% {
    background: purple;
  }
}

WordPress添加友链自助申请

前言

闲着无聊想弄个自助申请友链的功能,这样就不弄在评论区慢慢输入网站标题等文字了。

教程

因为我是登录才能评论所以以下代码只适用登录后才能评论。

1.首先在子主题的function.php 中添加如下代码。

function display_friendlink_form() {
    ob_start();
    ?>
    <style>
        #friendlink-form label {
            display: block;
            margin-bottom: 5px;
            font-weight: bold;
        }

        #friendlink-form input[type="text"],
        #friendlink-form input[type="url"] {
            width: 20%;
            padding: 10px;
            margin-bottom: 10px;
            border: 1px solid #ccc;
            border-radius: 4px;
            box-sizing: border-box;
        }

        #friendlink-form button[type="submit"] {
            padding: 10px 20px;
            background-color: #4CAF50;
            color: #fff;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }

        #friendlink-form button[type="submit"]:hover {
            background-color: #45a049;
        }

        #friendlink-notification {
            position: fixed;
            bottom: 20px;
            right: 20px;
            background-color: #4CAF50;
            color: #fff;
            padding: 10px;
            border-radius: 4px;
            display: none;
            z-index: 9999;
        }
    </style>

    <form id="friendlink-form" method="post">
        <div>
            <label for="website-name">网站名称:<input type="text" name="website-name" id="website-name" required></label>
        </div>
        <div>
            <label for="website-description">网站描述:<input type="text" name="website-description" id="website-description" required></label>
        </div>
        <div>
            <label for="website-url">网站地址:<input type="url" name="website-url" id="website-url" required></label>
        </div>
        <div>
            <label for="website-icon">网站图标:<input type="url" name="website-icon" id="website-icon" required></label>
        </div>
        <button type="submit" id="submit-friendlink" disabled>提交</button>
    </form>

    <div id="friendlink-notification"></div>

    <script>
        document.addEventListener('DOMContentLoaded', function() {
            var submitButton = document.getElementById('submit-friendlink');
            var websiteNameInput = document.getElementById('website-name');
            var websiteDescriptionInput = document.getElementById('website-description');
            var websiteUrlInput = document.getElementById('website-url');
            var websiteIconInput = document.getElementById('website-icon');

            function validateForm() {
                if (websiteNameInput.value.trim() !== '' &&
                    websiteDescriptionInput.value.trim() !== '' &&
                    websiteUrlInput.value.trim() !== '' &&
                    websiteIconInput.value.trim() !== '') {
                    submitButton.disabled = false;
                } else {
                    submitButton.disabled = true;
                }
            }

            websiteNameInput.addEventListener('input', validateForm);
            websiteDescriptionInput.addEventListener('input', validateForm);
            websiteUrlInput.addEventListener('input', validateForm);
            websiteIconInput.addEventListener('input', validateForm);

            document.getElementById('friendlink-form').addEventListener('submit', function(event) {
                event.preventDefault();

                var websiteName = websiteNameInput.value;
                var websiteDescription = websiteDescriptionInput.value;
                var websiteUrl = websiteUrlInput.value;
                var websiteIcon = websiteIconInput.value;

                var commentContent = '网站名称:' + websiteName + 'nn' +
                                     '网站描述:' + websiteDescription + 'nn' +
                                     '网站地址:' + websiteUrl + 'nn' +
                                     '网站图标:' + websiteIcon;

                var commentData = {
                    action: 'submit_friendlink',
                    websiteName: websiteName,
                    websiteDescription: websiteDescription,
                    websiteUrl: websiteUrl,
                    websiteIcon: websiteIcon,
                    post_id: <?php echo get_the_ID(); ?>,
                    user_id: <?php echo get_current_user_id(); ?>,
                };

                var xhr = new XMLHttpRequest();
                xhr.open('POST', '<?php echo admin_url('admin-ajax.php'); ?>', true);
                xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                xhr.onload = function() {
                    if (xhr.status === 200) {
                        var response = JSON.parse(xhr.responseText);
                        if (response.success) {
                            location.reload(); // 手动刷新页面
                        } else {
                            showNotification('你尚未登录请登录后重试。');
                        }
                    } else {
                        showNotification('你尚未登录请登录后重试。');
                    }
                };
                xhr.send(Object.keys(commentData).map(function(key) {
                    return encodeURIComponent(key) + '=' + encodeURIComponent(commentData[key]);
                }).join('&'));
            });
        });

        function showNotification(message) {
            var notification = document.getElementById('friendlink-notification');
            notification.textContent = message;
            notification.style.display = 'block';
            setTimeout(function() {
                notification.style.display = 'none';
            }, 2000);
        }
    </script>
    <?php
    return ob_get_clean();
}
add_shortcode('friendlink_form_new', 'display_friendlink_form');

function submit_friendlink_callback() {
    if (is_user_logged_in()) {
        $websiteName = $_POST['websiteName'];
        $websiteDescription = $_POST['websiteDescription'];
        $websiteUrl = $_POST['websiteUrl'];
        $websiteIcon = $_POST['websiteIcon'];
        $postID = $_POST['post_id'];
        $userID = $_POST['user_id'];

        if (empty($websiteName) || empty($websiteDescription) || empty($websiteUrl) || empty($websiteIcon)) {
            echo json_encode(array('success' => false));
            wp_die();
        }

        $commentData = array(
            'comment_post_ID' => $postID,
            'comment_author' => get_userdata($userID)->display_name,
            'comment_content' => "网站名称:$websiteNamenn网站描述:$websiteDescriptionnn网站地址:$websiteUrlnn网站图标:$websiteIcon",
            'comment_type' => '',
            'comment_parent' => 0,
            'user_ID' => $userID,
        );

        $commentID = wp_new_comment($commentData);
        if ($commentID) {
            echo json_encode(array('success' => true));
        } else {
            echo json_encode(array('success' => false));
        }
    } else {
        echo json_encode(array('success' => false));
    }

    wp_die();
}
add_action('wp_ajax_submit_friendlink', 'submit_friendlink_callback');
add_action('wp_ajax_nopriv_submit_friendlink', 'submit_friendlink_callback');

2.在友链页面合适的地方添加[friendlink_form_new] 短代码。

 

利用CN-Font-Split项目给中文字体分包

前言

之前的文章介绍了如何给WordPress添加自定义字体,今天教大家如何使用CN-Font-Split给中文字体进行分片

介绍

cn-font-split 是 中文网字计划 所使用的字体分包工具,通过高性能的各种技术将庞大的字体包拆分为适合网络分发的版本。经过四个版本的字体研究与代码迭代,这项技术在我们的网站中得到了充分的应用,实现了中文字体在 Web 领域的加载速度与效率的双飞跃。

项目地址

gitcode:https://gitcode.com/KonghaYao/cn-font-split

github:https://github.com/KonghaYao/cn-font-split

教程

1.首先去nodejs官网下载大于18版本的安装包,这里我下载的是19.9.0

2.其次就是打开安装包进行安装。

3.打开CMD输入以下代码安装项目

npm install @konghayao/cn-font-split
npm install @konghayao/cn-font-split -g # 如果使用命令行,推荐全局安装

4.继续输入以下命令进行分包

cn-font-split -i=../demo/public/SmileySans-Oblique.ttf -o=./temp

其中../demo/public/SmileySans-Oblique.ttf 可以替换成你字体的具体路径,./temp 替换成你想要分包出的文件的路径。

5.上传到网站的某个文件夹里。

6.调用方式:主题后台的页头代码或Head的html代码中添加如下代码

<link rel="stylesheet" href="https://你的域名/字体文件夹/result.css" />

7.查看result.css 文件中font-family 后面的文字就是你字体的名字。

8.在主题自定义css或子主题的css文件中添加如下代码

body {
    font-family: "字体名字", sans-serif;
}

这样就完成了字体的分包和调用。

 

WordPress添加自定义字体

前言

不少主题都有字体的设置,比如CoreNext,但是字体不太满意或者主题没有相关设置该怎么办?

教程

落霞孤鹜

BootCDN的字体库

BootCDN是Bootstrap 中文网支持并维护的前端开源项目免费 CDN 服务,致力于为 Bootstrap、jQuery、Angular、Vuejs 一样优秀的前端开源项目提供稳定、快速的免费 CDN 加速服务。

落霞孤鹜字体库网站链接:BootCDN - lxgw-wenkai-webfont

引入CSS

找到主题后台的自定义代码中的页面代码,也可以在head头部添加html代码

<link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/lxgw-wenkai-screen-webfont/1.7.0/style.min.css" />

添加CSS

如CoreNext主题可以在子主题设置如下代码,或者在主题设置里添加自定义CSS

body {
    font-family: "LXGW WenKai Screen", sans-serif;
}

如果是CoreNext主题,在sans-serif 和; 之间加上!important

自定义字体

添加自定义css

@font-face {
  font-family: '字体文件名';
  src: url('/zt/字体文件名.woff2') format('woff2');
  /* 添加其他字体格式,如woff、ttf等,以提供更好的兼容性 */
  /* src: url('字体文件路径') format('字体格式'); */
}

body {
    font-family: "字体名", sans-serif !important;
}

 

 

WordPress添加实时新闻文字版页面

前言

不久之前知乎的每日60秒读懂世界停止了更新,图片不能复制新闻内容很麻烦,所以今天教大家弄一个WordPress实时新闻文字版页面。

教程

1.首先下载文件到网站任意目录

2.在主题目录的function.php文件添加如下代码

function display_external_content() {
    $image_url= '域名/xinwen/data/60s_'.date('D').'.png';
    $url = '域名/xinwen';
    $response = wp_remote_get( $url );
    $image_html = '<div style="text-align: center;"><img src="' . $image_url . '" alt="Image" width="450" height="250" /></div>';
    $body = wp_remote_retrieve_body( $response );
    $text_html = '<p style="text-align: left;">' . $body. '</p>';
    $content_html = $image_html . $text_html;
    return $content_html;
}
add_shortcode( 'baidu_hot_new', 'display_external_content' );

3.在想要展示的页面中添加[baidu_hot_new] 短代码。

下载地址

 
WordPress添加每日新闻文字版
 

网站优化之关闭加载动画

前言

不少主题都自带加载动画,意思就是你网站页面尚未加载完成之前整个页面都会被加载动画所覆盖。

建议

相信不少朋友第一次听说了这个功能都会觉得不错,因为这会让访客在访问自己网站等待页面加载的时候不是空白页面而是有动画效果的。

但其实不然,因为主题中不可避免的会有调用其他网站的内容,比如css,js,图片等文件,但这些文件有些是很重要的,但有些是无关紧要的。

比如本人就在域名尚未备案之前使用的香港服务器搭建网站的时候,网站偶尔会出现加载小慢的时候,于是我就去主题后台开启了这个功能,但是首页出现速度反而更慢了。

于是我就排查其原因,发现是当初在美化网站加复制提醒的时候调用了其他网站的js文件导致了网站访问速度变慢,但是这个功能重要吗?其实也并不是那么重要。

所以为了网站的访问速度我关闭了主题的加载动画。

结语

首先在搭建网站的时候,能够不调用外部文件就不要调用外部文件。其次就是没必要的美化就不要加了不然就是对网站的负优化!

 

WordPress搜索屏蔽所有页面

前言

用WordPress搭建网站的站长都知道,WordPress自带的搜索路径为?s= ,这就导致搜索结果出来的时候会包含页面而不是只有文章内容,所以今天教大家如何让搜索结果屏蔽所有页面内容。

教程

我用的是CoreNext主题自带有子主题,如果没有子主题的要慎重修改。

将如下代码加到function.php 中即可

function search_filter_page($query) {
    if ($query->is_search) {
        $query->set('post_type', 'post');
    }
    return $query;
 }
add_filter('pre_get_posts','search_filter_page');

测试

加代码之前的效果:

图片[1]-新锐博客

加代码之后的效果:

图片[2]-新锐博客

 

WordPress右下角添加问候语

前言

看到他们不少人为WordPress添加了问候语,但是都是显示在页面的顶部,我觉得容易遮挡其他元素和存在时间很短,于是改了代码,让其显示在页面右下角并且显示五秒

代码

将代码放到主题后台的自定义代码中的页脚代码内即可。

<!--首页问候-->
<div id="greetingBox"></div>
<style>
    #greetingBox {
        position: fixed;
        bottom: 10px;
        right: 15px;
        width: 400px;
        text-align: right;
        z-index: 10000;
        pointer-events: none
    }

    #greeting {
        display: inline-block;
        position: relative;
        opacity: 0;
        bottom: -110px;
        padding: 5px 40px;
        border-radius: 50px;
        background-color: #fff;
        color: #000;
        font-size: small;
        transition: .5s;
        box-shadow: rgb(0 0 0 / 5%) 0 10px 20px
    }

    #greeting.shown {
        opacity: 1;
        bottom: 0
    }
</style>
<script>
    (() => {
    const greeting = [
        {
            realNode: {
                greeting: "您好,今天过得怎么样?",
                start_time: 0,
                end_time: 11
            }
        },
        {
            realNode: {
                greeting: "中午好👋, 记得好好吃午饭哦",
                start_time: 11,
                end_time: 13
            }
        },
        {
            realNode: {
                greeting: "下午好👋, 希望你下午工作顺利",
                start_time: 13,
                end_time: 18
            }
        },
        {
            realNode: {
                greeting: "晚上好👋, 在属于自己的时间好好放松😌~",
                start_time: 18,
                end_time: 24
            }
        }
    ];

    let e = greeting.length !== 0 ? greeting : [
        // 默认问候语数组
    ];

    let t = document.createElement("div");
    t.id = "greeting";
    setTimeout(() => {
        t.classList.add("shown");
    }, 1000);

    let i = document.querySelector("#greetingBox");
    i.appendChild(t);

    const n = new Date().getHours();
    let r = "";
    for (let t = 0; t < e.length; t++) {
        if (n >= e[t].realNode.start_time && n < e[t].realNode.end_time) {
            r = e[t].realNode.greeting;
            break;
        }
    }
    t.innerHTML = r;
    setTimeout(() => {
        t.classList.remove("shown");
        setTimeout(() => {
            i.remove();
        }, 500);
    }, 5000);
})();
</script>

WordPress添加观影和书单插件 - WP-Douban

前言

之前写过一篇追剧页面的function代码,现在给大家推荐一个可以添加书单,观影页面的插件。

教程

首先上传插件文件,然后到插件的设置页面填写豆瓣的ID和申请的KEY。

记得申请KEY的时候需要填写应用简介,请用英文不要用中文,否则会提示需要你告知他们将会如何使用API。

设置的时候静态文件和开启分类不要勾选,否则可能不会显示(至少我的是这样的,目前不知道是什么原因)

链接地址

具体的教程地址:https://fatesinger.com/101050

项目开源地址:https://github.com/bigfa/wp-douban

下载地址:https://github.com/bigfa/wp-douban/releases/tag/v4.4.3

 

给WordPress添加随机文章页面

前言

之前介绍过给你的网站添加一个Ctrl+D收藏引导,它的发现更多是回到首页,但是我想让它显示随机文章。

教程

主题有子主题的可以加function代码添加到子主题的function.php 中,没有的话慎重修改主题代码。

首先将如下代码添加到function.php 中:

function redirect_to_random_post() {
    if ( is_page( 'your-page-slug' ) ) { // 将 'your-page-slug' 替换为您想要跳转到随机文章的页面的别名或ID
        $args = array(
            'orderby' => 'rand',
            'posts_per_page' => 1
        );
        $random_post = new WP_Query( $args );
        if ( $random_post->have_posts() ) {
            while ( $random_post->have_posts() ) {
                $random_post->the_post();
                $url = get_permalink();
            }
        }
        wp_reset_postdata();
        wp_redirect( $url );
        exit;
    }
}
add_action( 'template_redirect', 'redirect_to_random_post' );

再到WordPress后台中创建新页面,然后在页面的编辑器中选择文本,最后将[template_redirect] 添加到页面中。

接下来访问页面就可以跳转到随机文章啦。

WordPress添加2D模型看板娘

前言

WordPress相比较hexo首页的两边有点空的感觉,所以我们可以加点东西,比如可爱的看板娘

界面截图

图片[1]-新锐博客

教程

首先下载Live2D看板娘的主体文件,然后到CoreNext主题的后台添加页头代码

<link rel="stylesheet" type="text/css" href="/live2d/assets/waifu.css"/>

再到页脚代码里添加如下代码

  <div class="waifu">
        <div class="waifu-tips"></div>
        <canvas id="live2d" class="live2d"></canvas>
        <div class="waifu-tool">
            <span class="fui-home"></span>
            <span class="fui-chat"></span>
            <span class="fui-eye"></span>
            <span class="fui-user"></span>
            <span class="fui-photo"></span>
            <span class="fui-info-circle"></span>
            <span class="fui-cross"></span>
        </div>
    </div>
    
    <script src="/live2d/assets/waifu-tips.js"></script>
    <script src="/live2d/assets/live2d.js"></script>
    
    <script type="text/javascript">
        live2d_settings['modelId'] = 1;
        live2d_settings['modelTexturesId'] = 87;
    	initModel("/live2d/assets/waifu-tips.json")
    </script>

 

 

 

如果想要修改看板娘的设置可以到live2d -assets -waifu-tips.js 中修改还有waifu-tips.json 文件里修改。

文件下载

Live2D

利用function和短代码添加文章列表页面

前言

虽然已经有站点地图插件生成出sitemap界面了,但是它包含了分类和标签,而且很多插件不支持按照月份归类,所以我就自己想办法搞了一个页面,下面是教程。

教程

首先将如下代码放到主题的function.php内,然后将短代码放到需要展示的页面中

代码如下

// 注册文章列表短代码
function wp_post_list_shortcode($atts) {
    // 获取所有文章
    $posts = get_posts(array(
        'numberposts' => -1
    ));

    // 初始化归档数组
    $archives = array();

    // 遍历所有文章
    foreach ($posts as $post) {
        // 获取文章发布日期
        $date = get_the_date('Ym', $post->ID);

        // 如果归档数组中没有该日期,则添加
        if (!array_key_exists($date, $archives)) {
            $archives[$date] = array();
        }

        // 将文章添加到对应的归档日期中
        array_push($archives[$date], $post);
    }

    // 初始化输出字符串
    $output = '';

    // 遍历归档数组,按年月添加文章列表
    $prev_year = '';
    $prev_month = '';
    foreach ($archives as $date => $posts) {
        // 获取年份和月份
        $year = substr($date, 0, 4);
        $month = substr($date, 4, 2);

        // 如果年份不同,则添加一级标题
        if ($year != $prev_year) {
            if ($prev_year != '') {
                $output .= '';
            }
            $output .= '<h2>' . $year . '年</h2>';
        }

        // 如果月份不同,则添加二级标题
        if ($month != $prev_month) {
            if ($prev_month != '') {
                $output .= '';
            }
            $output .= '<h3>' . $month . '月</h3>';
        }

        // 添加文章列表
        foreach ($posts as $post) {
            $output .= '<li><a href="' . get_permalink($post->ID) . '">' . $post->post_title . '</a></li>';
        }

        // 更新年份和月份
        $prev_year = $year;
        $prev_month = $month;
    }

    // 添加最后一个二级标题和一级标题的闭合标签
    if ($prev_month != '') {
        $output .= '';
    }
    if ($prev_year != '') {
        $output .= '';
    }

    // 返回输出字符串
    return $output;
}
add_shortcode('wp_archives', 'wp_post_list_shortcode');

短代码:[wp_archives]

WordPress添加文章AI摘要

前言

相信很多人和我一样有阅读障碍,稍微内容长一点的阅读起来就很嫌麻烦,所以AI自动摘要是很有必要的,下面就教大家如何给WordPress添加文章AI摘要

本教程适用于CoreNext主题,其他主题请根据情况修改。

界面截图

图片[1]-新锐博客

教程

  1. 首先介绍本次内容的主人公:https://github.com/zhheo/Post-Abstract-AI
  2. 其次去爱发电购买KEY秘钥:https://afdian.net/item/f18c2e08db4411eda2f25254001e7c00
  3. 用购买的KEY去后台绑定域名:https://summary.zhheo.com/
  4. 将如下代码添加到主题后台的自定义页头代码 中
<link rel="stylesheet" href="https://cdn1.tianli0.top/gh/zhheo/Post-Abstract-AI@0.15.2/tianli_gpt.css">
<script>
let tianliGPT_postSelector = '.content-warp';
let tianliGPT_key = '5Q5mpqRK5DkwT1X9Gi5e';
</script>
<script src="https://cdn1.tianli0.top/gh/zhheo/Post-Abstract-AI@0.15.2/tianli_gpt.js"></script>

其中的tianliGPT_key 就是你购买的KEY,tianliGPT_postSelector是你主题的文章内容的选择器,可以通过F12查看,具体教程在下方,然后强制刷新下网页访问文章就可以在顶部看到文章AI摘要了。

获取tianliGPT_postSelector的教程:https://flowus.cn/zhheo/share/7a353126-f225-4e5c-8c11-f5adefe85b7f

进阶玩法

由其他大神提供的TianliGpt的进阶玩法:https://hub.yzuu.cf/qxchuckle/Post-Summary-AI

CoreNext_Beautiful - CoreNext主题的美化插件

前言

之前就讲过关于CoreNext主题美化,但是对于很多人来说有点麻烦,所以这次搞了个插件。

功能

技术有限,只能更新四个美化

1.彩虹滚动条

2.首页文章鼠标停留悬浮

3.文章页图片鼠标停留悬浮

4.友链模块美化

界面截图

图片[1]-新锐博客

下载地址

CoreNext_Beautiful

WordPress侧边栏添加节日倒计时

前言

临近春节,所以突发奇想想要给网站加一个节日倒计时,看看距离春节还有多久

代码

WordPress侧边栏添加自定义Html并且加入以下代码

<span id="ActivityDate">2024-02-10 00:00:00</span>
<script>
    // 获取id
    var ActivityDate = document.getElementById("ActivityDate");
    function timepiece(key){
        var datatime = /^[d]{4}-[d]{1,2}-[d]{1,2}( [d]{1,2}:[d]{1,2}(:[d]{1,2})?)?$/ig,str='',s;
        // 正则验证日期格式是否正确
        if(!key.match(datatime)){
            console.log('日期参数错误,请按格式填写,如 1996-10-22 24:00:00');
            return
        }
        // 当前日期减去活动日期,判断是否超出
        var sec = (new Date(key.replace(/-/ig,'/')).getTime() - new Date().getTime())/1000;
        if(sec < 0){
            ActivityDate.innerHTML = "<span style=" + "color:red;" + ">" + "新的一年开始啦,祝大家新年快乐!" + "</span>";
            return
        }
        s = {
            '天':sec/24/3600,
            '时':sec/3600%24,
            '分':sec/60%60,
            '秒':sec%60
        }
        for(i in s){
            if(Math.floor(s[i]) > 0) str += Math.floor(s[i]) + i;
        }
        if(Math.floor(sec) == 0){
            str='0秒';
        }
        // 距离活动结束时间显示到页面
        ActivityDate.innerHTML = "距离2024年春节还有:"+"<span style=" + "color:#4ad564;" + ">" + str + "</span>";
        // 每隔1秒更新一次
        setTimeout(function(){
            timepiece(key)
        },1000)
    }
    timepiece(ActivityDate.innerHTML);
</script>

CoreNext主题美化合集

前言

  • 本次美化教程部分来源于CorePress主题美化合集,再加上本人的修改而成。
  • 本章内容不定时更新,有好的美化教程第一时间分享出来,记得经常光顾本站!
  • 本章内容只适合CoreNext主题,其他主题暂未测试,如有问题自行调整。

教程

所有Css代码放到子主题文件夹中的Css文件夹内的main.css内即可。

更新时间

最新更新时间:2024年6月19日23:06:21

代码

申请友链模块

css代码如下:

/* 友链申请按钮美化 */
.application-url {
    padding: 5px 10px;
    color: white !important;
    text-decoration: none;
    border-radius: 50px;
    background: linear-gradient(to right, #fd0808, #df05ed);
    background-size: 200% auto;
    animation: flowingGradient 3s ease-in-out infinite;
    opacity: 1;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
    filter: brightness(130%);
}
.application-url:hover {
    transform: scale(1.1);
    -webkit-transform: scale(1.1);
    -moz-transform: scale(1.1);
    -o-transform: scale(1.1);
    -ms-transform: scale(1.1);
}
@keyframes flowingGradient {
  0% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0% 50%;
  }
}
.application-url .friends-title > div  {
    line-height: 32px;
}
评论输入框添加背景图

css代码如下:

/*评论背景图*/
textarea.comment-textarea[data-v-1ef8f4cc] {
    background-color:transparent;background:linear-gradient(rgba(0, 0, 0, 0.05), rgba(0, 0, 0, 0.05)),url(/api/img/comment.png) right 10px bottom 10px no-repeat;
    -moz-transition:ease-in-out 0.45s;
    -webkit-transition:ease-in-out 0.45s;
    -o-transition:ease-in-out 0.45s;
    -ms-transition:ease-in-out 0.45s;
    transition:ease-in-out 0.45s;
}
textarea.comment-textarea[data-v-1ef8f4cc]:focus {
    background-position-y:789px;
    -moz-transition:ease-in-out 0.45s;
    -webkit-transition:ease-in-out 0.45s;
    -o-transition:ease-in-out 0.45s;
    -ms-transition:ease-in-out 0.45s;
    transition:ease-in-out 0.45s;
}

请将其中的/wp-content/uploads/2023/03/comment.png 替换为自己的图片地址

效果如下:

图片[1]-新锐博客

文章页图片悬浮

css代码如下:

图片具体文字太近,加了一个 margin 属性,不需要的可以去掉

/*文章图片悬浮效果*/
.core-next-img {
    transition: All 0.4s ease-in-out;
    -webkit-transition: All 0.4s ease-in-out;
    -moz-transition: All 0.4s ease-in-out;
    -o-transition: All 0.4s ease-in-out;
    margin: 10px 0;
}
.core-next-img:hover {
    transform: translate(0, -10px);
    -webkit-transform: translate(0, -10px);
    -moz-transform: translate(0, -10px);
    -o-transform: translate(0, -10px);
    -ms-transform: translate(0, -10px);
    box-shadow:5px 5px 10px gray;   
} 
添加彩色滚动条

css代码如下:

/**彩色滚动条*/
::-webkit-scrollbar {
    width: 8px;  
    height: 1px;
}
::-webkit-scrollbar-thumb {
    background-color: #12b7f5;
    background-image: -webkit-linear-gradient(45deg, rgba(255, 93, 143, 1) 25%, transparent 25%, transparent 50%, rgba(255, 93, 143, 1) 50%, rgba(255, 93, 143, 1) 75%, transparent 75%, transparent);
}
::-webkit-scrollbar-track {
    -webkit-box-shadow: inset 0 0 5px rgba(0,0,0,0.2);
    background: #f6f6f6;
}
首页文章悬浮效果

css代码如下:

.post-list .post-item:hover {
    opacity: 1;
    z-index: 99;
    border-radius: 20px;
    transform: translateY(-5px);
    box-shadow: 0 3px 20px rgb(0 0 0 / 25%);
    animation: index-link-active 1s cubic-bezier(0.315, 0.605, 0.375, 0.925) forwards;
}
.post-list .post-item:hover .post-item__cover {
  transform: translateY(-100%);
}
.post-list .post-item__cover {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  transition: transform 0.3s ease;
  transform: translateY(0);
}
.post-list .post-item__title {
  position: absolute;
  bottom: 20px;
  left: 20px;
  color: #fff;
  font-size: 20px;
  font-weight: 600;
}
底部菜单美化

本代码来源于诺言博客

css代码如下:

/*CSS 网站底部自定义按钮美化开始*/
:root{--theme-color:#f04494;
--focus-shadow-color:rgba(240,68,148,.4);
--mian-max-width:1200px;}.github-badge {
    display: inline-block;
    border-radius: 4px;    text-shadow: none;    font-size: 12px;    color: #fff;    line-height: 15px;    margin-bottom: 5px;}.badge-subject {
    display: inline-block;    background-color: #4d4d4d;    padding: 4px 4px 4px 6px;
    border-top-left-radius: 4px;
    border-bottom-left-radius: 4px;}.github-badge .bg-blue {
    background-color: #007ec6;}.github-badge .bg-brightgreen {
    background-color: #4dc820;}.github-badge .bg-blueviolet {
    background-color: #8833d7;}.github-badge .badge-value {
    display: inline-block;    padding: 4px 6px 4px 4px;
    border-top-right-radius: 4px;
    border-bottom-right-radius: 4px;}.github-badge .bg-orange {
    background-color: orange;}.github-badge .bg-red {
    background-color: red;}
    /*CSS 网站底部自定义按钮美化结束*/
    

再进入小工具的底部左侧添加自定义Html,代码如下

<div class="github-badge">
<span class="badge-subject bg-blue"><a style="color:#fff" href="#" target="_blank">友链申请</a>
</span>
<span class="badge-subject bg-blueviolet"><a style="color:#fff" href="#" target="_blank">网站地图</a>
</span>
<span class="badge-subject bg-green"><a style="color:#fff" href="#" target="_blank">留言建议</a>
</span>
<span class="badge-subject bg-orange"><a style="color:#fff" href="#" target="_blank">免责申明</a>
</span>
</div>

将其中的#换成自己的链接即可

底部黑暗明亮模式切换

首先找到主题文件夹下的/static/css/dark.css 添加如下代码

.core-footer{background: #22292d !important;color: #b3c0ce !important;}

然后添加CSS代码

css代码如下:

/** 修改底部颜色 */
.core-footer {
   background: #fff;
   color: #999;
   box-shadow: 0 0.5px 0.5px 1px rgb(0 0 0 / 10%);
    padding: 20px 30px 30px 30px;
}
.core-footer a {
   color: unset!important;;
}
.footer-right {
   margin-bottom: unset!important;;
}
.core-footer a:hover {
    color:var(--MaincolorHover) !important;
}
文章底部添加时间和时效性

css代码如下

/**文章添加时间和时效性*/
#comment_addface { 
    position: relative 
} 
.conment-face-plane { 
    position: absolute; 
    transition: .15s; 
    box-shadow: 0 5px 10px rgba(0, 0, 0, .2); 
    border: 1px solid rgba(0, 0, 0, .2); 
    border-radius: 6px; 
    top: 100%; 
    padding: 10px; 
    background: #fff; 
    max-width: 300px; 
    z-index: 9999; 
    opacity: 1; 
    visibility: hidden 
} 
.popover-btn-face { 
    margin-top: 10px 
} 
.popover-btn { 
    border-radius: 4px; 
    display: inline-block; 
    transition: .15s; 
    vertical-align: middle; 
    padding: .3em .5em; 
    text-align: center; 
    line-height: 1.44; 
    border: none; 
    outline: none; 
    cursor: pointer 
}

再到子主题的template文件夹内的single.php添加如下代码

<div class="c-alert c-alert-error">本文最后更新于<code><?php echo the_time('Y-m-j');
?></code>部分内容具有时效性,如有失效,请留言</div>
LOGO扫光

代码如下

.home-img {
    position:relative;
    float:left;
    margin-right:10px;
    padding:5px 0;
    overflow:hidden;
}
.home-img  a:before {
    content:"";
    position:absolute;
    left:-665px;
    top:-460px;
    width:200px;
    height:15px;
    background-color:rgba(255,255,255,.5);
    -webkit-transform:rotate(-45deg);
    -moz-transform:rotate(-45deg);
    -ms-transform:rotate(-45deg);
    -o-transform:rotate(-45deg);
    transform:rotate(-45deg);
    -webkit-animation:searchLights 1s ease-in 1s infinite;
    -o-animation:searchLights 1s ease-in 1s infinite;
    animation:searchLights 2s ease-in 2s infinite;
}
@-webkit-keyframes searchLights {
    0% { left:-100px; top:0; }
    to { left:120px; top:100px; }
}
@-o-keyframes searchLights {
    0% { left:-100px; top:0; }
    to { left:120px; top:100px; }
}
@-moz-keyframes searchLights {
    0% { left:-100px; top:0; }
    to { left:120px; top:100px; }
}
@keyframes searchLights {
    0% { left:-100px; top:0; }
    to { left:120px; top:100px; }
}
去除侧边栏站长工具中的数据统计

css代码如下

.webmaster-widget .webmaster-site-info{
    display: none;
}
导航栏添加背景图和透明效果

首先下载背景图:

图片[2]-新锐博客

css代码如下:

your img api 替换为你的图片链接

/**  导航栏添加背景图和透明效果  */
header {
    background-color: rgba(255, 255, 255, 0.96);
    background-image: url(your img api);
    background-position: center right;
    background-size: auto 100%;
    box-shadow: 0px 5px 40px 0px rgba(17,58,93,0.1);
}
.menu-header-plane > ul {
   background-color: rgba(255, 255, 255, 0.96);
    background: unset;
}
首页文章添加间距

css代码如下

.post-item {
  margin-bottom: 20px;
}
实时监测页面是否离开并自动更改标题

将如下代码添加到后台主题设置-插入代码 - 页头代码

<script>
document.addEventListener('visibilitychange', function () {
if (document.visibilityState == 'hidden') {
    normal_title = document.title;
    document.title = 'w(゚Д゚)w 宝~请不要离开!';
} else document.title = normal_title;
});
</script>

其中的w(゚Д゚)w 宝~请不要离开!normal_title 分别为离开时和返回时显示的标题,可以根据自己的喜好修改

底部ICP备案信息居中

有不少地区或者服务商要求备案信息放在底部居中

将CSS代码放入子主题的CSS文件中

.core-footer {
  position: relative;
}
.icp-warp {
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
}
侧边栏添加欢迎词

如下图效果

图片[3]-新锐博客

侧边栏添加如下自定义html代码

<div id="scroll-broadcast">
    <div id="container-box-1">
        <div class="container-box-1-1">每天来逛逛我的博客,会让你</div>
        <div id="flip-box-1">
            <div><div class="flip-box-1-1">生活也美好了!</div></div>
            <div><div class="flip-box-1-2">心情也舒畅了!</div></div>
            <div><div class="flip-box-1-3">走路也有劲了!</div></div>
            <div><div class="flip-box-1-4">腿也不痛了!</div></div>
            <div><div class="flip-box-1-5">腰也不酸了!</div></div>
            <div><div class="flip-box-1-6">工作也轻松了!</div></div>
        </div>
        <div class="container-box-1-2">你好我也好,不要忘记哦!</div>
    </div>
</div>
<style type="text/css">
    #scroll-broadcast {margin: -10px;}
    #container-box-1{color: #4c5864;font-weight: bold; border-radius: var(--border-hd);text-transform:uppercase;width:100%;font-size:16px;line-height:50px;text-align:center;padding: 10px;background: linear-gradient(45deg, #C7F5FE 10%, #C7F5FE 40%, #FCC8F8 40%, #FCC8F8 60%, #EAB4F8 60%, #EAB4F8 65%, #F3F798 65%, #F3F798 90%);}
    #flip-box-1{overflow:hidden;height:50px;border-radius:99px}
    #flip-box-1 div{height:50px}
    #flip-box-1>div>div{color:#fff;display:inline-block;text-align:center;height:50px;width:100%}
    #flip-box-1 div:first-child{animation:show 8s linear infinite}
    .flip-box-1-1{background-image:linear-gradient(to right,#fa709a 0,#fee140 100%)}
    .flip-box-1-2{background-image: linear-gradient(120deg, #e0c3fc 0%, #8ec5fc 100%);}
    .flip-box-1-3{background-image: linear-gradient(to right, #b8cbb8 0%, #b8cbb8 0%, #b465da 0%, #cf6cc9 33%, #ee609c 66%, #ee609c 100%);}
    .flip-box-1-4{background-image: linear-gradient(to right, #f78ca0 0%, #f9748f 19%, #fd868c 60%, #fe9a8b 100%);}
    .flip-box-1-5{background-image: linear-gradient(to right, #74ebd5 0%, #9face6 100%);}
    .flip-box-1-6{background-image: linear-gradient(to top, #9795f0 0%, #fbc8d4 100%);}
    @keyframes show{
        0%{margin-top:-300px}
        5%{margin-top:-250px}
        16.666%{margin-top:-250px}
        21.666%{margin-top:-200px}
        33.332%{margin-top:-200px}
        38.332%{margin-top:-150px}
        49.998%{margin-top:-150px}
        54.998%{margin-top:-100px}
        66.664%{margin-top:-100px}
        71.664%{margin-top:-50px}
        83.33%{margin-top:-50px}
        88.33%{margin-top:0}
        99.996%{margin-top:0}
    100%{margin-top:300px}
    }
</style>
文章版权信息

将如下代码添加到主题设置中

<fieldset style=" border: 1.5px dashed #008cff; padding: 10px; border-radius: 5px; line-height: 2em;font-weight: 700;color: var(--key-color);background-color: var(--body-bg-color);">
      <legend align="center" style=" margin-bottom: -2px;width: 30%;text-align: center; background-color: #008cff; border-radius: 999px; background-image: linear-gradient(to right, #FFCC99, #FF99CC);border: 1.5px dashed #008cff;">
        版权声明
      </legend>
      <span class="btn-info btn-xs">1</span> 本文章标题:<span style="color: #3333ff"><span style="color: #09ace2; font-size: 15px"><strong>#postname# </strong></span></span><br>
      <span class="btn-info btn-xs">2</span> 本文章地址:<font color="#09ace2">#url# </font><br>
 <span class="btn-info btn-xs">3</span> 本网站的文章部分内容可能来源于网络,仅供大家学习与参考,如有侵权,请发送邮件至<font color="#09ace2">xxx@qq.com</font>进行删除处理。<br>
      <span class="btn-info btn-xs">4</span> 本站一切资源不代表本站立场,并不代表本站赞同其观点和对其真实性负责。<br>
            <span class="btn-info btn-xs">5</span> 如您发现本站提供资源链接失效或有违规现象,请联系我们处理。<br>
    </fieldset>

WordPress 添加复制版权提示

前言

今天教大家在别人复制网页内容的时候弹窗提示他人转载表明出处。

方法

添加如下代码到页脚代码中

<script>
document.addEventListener('copy', function(e) {
    e.preventDefault();
    var copyText = window.getSelection().toString();
    var messageWithCredit =copyText;
    e.clipboardData.setData('text', messageWithCredit);

    // 显示复制成功通知
    new Vue({
        data: function () {
            this.$notify({
                title: "复制提示",
                message: "复制成功,请标注转载的出处!",
                position: 'bottom-right',
                offset: 50,
                showClose: true,
                type: "success"
            });
            return { visible: false };
        }
    });
});
</script>

 

WordPress视频插件 - smartideo

前言

  • 在使用wordpress写文章内容时,有时想调用腾讯,优酷,b站等平台的在线视频
  • 这款smartideo视频插件,使用非常简单就能调用到优酷,b站,腾讯等平台的视频。

教程

直接在编辑器中填写视频的URL地址就可以了,插件会自动识别。

结尾

CorePress主题美化合集

前言

  • 本次美化教程均来源于其他优秀站点,本人只是把它们整合到一起罢了。
  • 本章内容不定时更新,有好的美化教程第一时间分享出来,记得经常光顾本站!
  • 本章内容只适合Corepress主题,其他主题暂未测试,如有问题自行调整。

教程

免费版可以将下方的css填写到主题的自定义css 中,Pro版本放到子主题的style.css 中即可。

更新时间

最新更新时间:2023年4月30日22:20:58

代码

首页模仿mac样式

本代码来源于corepress主题官网:https://www.lovestu.com/corepressmac.html

/** 首页模仿mac样式 */
:root {
    --border-hd: 10px !important;
}
body header {
    box-shadow: 0 0 20px 0 rgb(0 0 0 / 5%);
}
.post-list-page-plane {
    background-color: #fff;
}
body .widget-title {
    border-bottom: none;
}
.friend-links {
    overflow: hidden;
}
body .widget-title:before {
    width: 12px;
    height: 12px;
    transform: none;
    background: #fc625d;
    border-radius: 50%;
    top: 10px;
}
body .widget-title:after {
    background-color: #fdbc40;
    width: 12px;
    height: 12px;
    transform: none;
    border-radius: 50%;
    left: 20px;
    top: 10px;
}
body .widget-title {
    padding-left: 40px;
}
.widget-admin-author-contact-item-icon {
    border-bottom-left-radius:2px!important;
}

申请友链模块

本代码来源于阿蛮君博客:https://www.amjun.com/1830.html

css代码如下:

1.申请按钮美化

/* 按钮美化 */
.friend-links-apply {
    padding: 5px 10px;
    color: white !important;
    text-decoration: none;
    border-radius: 50px;
    background: linear-gradient(to right, #fd0808, #df05ed);
    background-size: 200% auto;
    animation: flowingGradient 3s ease-in-out infinite;
    opacity: 1;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
    filter: brightness(130%);
}
.friend-links-apply:hover {
    transform: scale(1.1);
    -webkit-transform: scale(1.1);
    -moz-transform: scale(1.1);
    -o-transform: scale(1.1);
    -ms-transform: scale(1.1);
}
@keyframes flowingGradient {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}
.friend-links .list-plane-title > div {
    line-height: 30px;
}
.fa-paper-plane:hover { color:red; }

2.按钮悬浮

/* 友链a标签放大效果 */
.friend-links-list a:hover {
    transform: scale(1.1);
    -webkit-transform: scale(1.1);
    -moz-transform: scale(1.1);
    -o-transform: scale(1.1);
    -ms-transform: scale(1.1);
}

3.多行友链添加空隙

/** 友情链接多行时显示过于紧凑 **/
.friend-links-list {
   padding: 10px 10px 10px 15px !important;
}
.friend-links-list a {
   margin-bottom: 10px;
}

4.手机底部导航并美化(按需添加)

@media screen and (max-width: 800px) {
  .friend-links { display: block !important; }
  .friend-links .list-plane-title { padding: 0px; }
  .friend-links-list img { display: none !important; }
  .friend-links .list-plane-title > div {
      padding: 5px 0px 5px 15px;
      font-size: 16px;
      clear: both;
  }
  .list-plane-linksdescribe, .friend-links-apply{ display:none!important }
  .friend-links-list {
      padding: 10px !important;
      margin: 0 5px;
      display: block;
  }
  .friend-links-list a {
      font-size: 12px;
      margin-bottom: 5px;
      color: #262525!important;
      -webkit-tap-highlight-color: transparent;
  }
  .friend-links-item { margin-right: 0px; }
  .friend-links-item:not(:first-child):before {
      content: "";
      width: 4px;
      height: 4px;
      margin: 0 .3em;
      border-radius: 50%;
      display: inline-block;
      vertical-align: middle;
      background:#262525;
      opacity: .3;
      vertical-align: .2em;
  }
}

评论输入框添加背景图

本代码来源于阿蛮君博客:https://www.amjun.com/1686.html

/*评论背景图*/
textarea#comment {
    background-color:transparent;
    background:linear-gradient(rgba(0, 0, 0, 0.05), rgba(0, 0, 0, 0.05)),url(/wp-content/uploads/2023/03/comment.png) right 10px bottom 10px no-repeat;
    -moz-transition:ease-in-out 0.45s;
    -webkit-transition:ease-in-out 0.45s;
    -o-transition:ease-in-out 0.45s;
    -ms-transition:ease-in-out 0.45s;
    transition:ease-in-out 0.45s;
}
textarea#comment:focus {
    background-position-y:789px;
    -moz-transition:ease-in-out 0.45s;
    -webkit-transition:ease-in-out 0.45s;
    -o-transition:ease-in-out 0.45s;
    -ms-transition:ease-in-out 0.45s;
    transition:ease-in-out 0.45s;
}

请将其中的/wp-content/uploads/2023/03/comment.png 替换为自己的图片地址

图片[1]-新锐博客

优化上一篇下一篇样式

本代码来源于阿蛮君博客:https://www.amjun.com/1685.html

/** 上一篇下一篇优化 */
.post-turn-page-main a {
    white-space: nowrap;
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
}

文章页图片悬浮

本代码来源于阿蛮君博客:https://www.amjun.com/1658.html

/*文章图片悬浮效果*/
.post-content-content img {
    transition: All 0.4s ease-in-out;
    -webkit-transition: All 0.4s ease-in-out;
    -moz-transition: All 0.4s ease-in-out;
    -o-transition: All 0.4s ease-in-out;
    margin: 10px 0;
}
.post-content-content img:hover {
    transform: translate(0, -10px);
    -webkit-transform: translate(0, -10px);
    -moz-transform: translate(0, -10px);
    -o-transform: translate(0, -10px);
    -ms-transform: translate(0, -10px);
    box-shadow:5px 5px 10px gray;   
}

添加彩色滚动条

本代码来源于阿蛮君博客:https://www.amjun.com/1653.html

/**彩色滚动条*/
::-webkit-scrollbar {
    width: 8px;  
    height: 1px;
}
::-webkit-scrollbar-thumb {
    background-color: #12b7f5;
    background-image: -webkit-linear-gradient(45deg, rgba(255, 93, 143, 1) 25%, transparent 25%, transparent 50%, rgba(255, 93, 143, 1) 50%, rgba(255, 93, 143, 1) 75%, transparent 75%, transparent);
}
::-webkit-scrollbar-track {
    -webkit-box-shadow: inset 0 0 5px rgba(0,0,0,0.2);
    background: #f6f6f6;
}

文章底部彩色标签

本代码来源于技术SOLO博客:https://www.jssolo.com/note/903

/** 文章底部彩色标签 */
.post-tags{margin-bottom: 10px}
.post-tags a{
    padding: 4px 10px;
    background-color: #36a1d2;
    color: white;
    font-size: 12px;
    margin: 0 5px 5px 0;
    border-radius: 10px;
    display: inline-block
}
.post-tags a:nth-child(5n){background-color: #7d43da}
.post-tags a:nth-child(5n+1){background-color: #d74e4b}
.post-tags a:nth-child(5n+2){background-color: #dc9e3a}
.post-tags a:nth-child(5n+3){background-color: #30ce67}
.post-tags a:nth-child(5n+4){background-color: #339ecf}
.post-tags a:hover{background-color: #494949}
.tag-cloud-link:before {content: unset;}

底部菜单美化

本代码来源于阿蛮君博客:https://www.amjun.com/1860.html

/** 底部菜单美化 */
.menu-footer-list {
    display: inline-block;
    border-radius: 4px;
    font-size: 12px;
    color: #fff !important;
    line-height: 15px;
    margin-bottom: 5px;
}
.menu-footer-list .menu-item a {
    font-size: 13px;
}
.menu-footer-list .menu-item{
    display: inline-block;
    background-color: #4d4d4d;
    padding: 4px 4px 4px 6px;
    border-radius: 4px 0 0 4px;
    margin-right: 5px;
}
.menu-footer-list li:nth-child(6n+1) {background-color: #4dc820}
.menu-footer-list li:nth-child(6n+2) {background-color: #8833d7}
.menu-footer-list li:nth-child(6n+3) {background-color: orange}
.menu-footer-list li:nth-child(6n+4) {background-color: #e91515}
.menu-footer-list li:nth-child(6n+5){background-color: #007ec6}
.menu-footer-list li:nth-child(6n) {background-color: #e323c2}
#menu-footer-nav li:hover {
    transform: scale(1.1);
    -webkit-transform: scale(1.1);
    -moz-transform: scale(1.1);
}

实时监测页面是否离开并自动更改标题
<script>
document.addEventListener('visibilitychange', function () {
    if (document.visibilityState == 'hidden') {
        normal_title = document.title;
        document.title = 'w(゚Д゚)w 宝~请不要离开!';
    } else {
        document.title = normal_title;
    }
});
</script>

添加导航栏背景图和透明效果

图片[2]-新锐博客

/** 导航栏添加背景图和透明效果  */
header {
    background-color: rgba(255, 255, 255, 0.96);
    background-image: url(your_img_url);
    background-position: center right;
    background-size: auto 100%;
    box-shadow: 0px 5px 40px 0px rgba(17,58,93,0.1);
}
.menu-header-plane > ul {
    background-color: rgba(255, 255, 255, 0.96);
}

首页文章添加间距
.post-item {
    margin-bottom: 20px;
}

底部ICP备案信息居中
.core-footer {
    position: relative;
}
.icp-warp {
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
}

侧边栏添加滚动播报
<div id="scroll-broadcast">
    <div id="container-box-1">
        <div class="container-box-1-1">每天来逛逛我的博客,会让你</div>
        <div id="flip-box-1">
            <!-- 滚动内容结构保持不变 -->
        </div>
        <div class="container-box-1-2">你好我也好,不要忘记哦!</div>
    </div>
</div>
<style>
    #scroll-broadcast {margin: -10px;}
    #container-box-1{
        background: linear-gradient(45deg, #C7F5FE 10%, #FCC8F8 40%, #EAB4F8 60%, #F3F798 90%);
        border-radius: 10px;
        padding: 10px;
    }
    /* 其他样式保持不变 */
</style>

底部黑暗明亮模式切换

本代码来源于阿蛮君博客:https://www.amjun.com/1462.html

.footer-plane{background: #22292d !important;color: #b3c0ce !important;}
/** 修改底部颜色 */
.footer-plane {
   background: #fff;
   color: #999;
   box-shadow: 0 0.5px 0.5px 1px rgb(0 0 0 / 10%);
    padding: 20px 30px 30px 30px;
}
.footer-plane a {
   color: unset!important;
}
.footer-aside-box {
   margin-bottom: unset!important;
}
.footer-info a:hover {
    color:var(--MaincolorHover) !important;
}

文章版权信息
<fieldset style="border: 1.5px dashed #008cff; padding: 10px; border-radius: 5px; line-height: 2em;font-weight: 700;color: var(--key-color);background-color: var(--body-bg-color);">
    <legend align="center" style="margin-bottom: -2px;width: 30%;text-align: center; background-color: #008cff; border-radius: 999px; background-image: linear-gradient(to right, #FFCC99, #FF99CC);border: 1.5px dashed #008cff;">
        版权声明
    </legend>
    <span class="btn-info btn-xs">1</span> 本文章标题:<span style="color: #3333ff"><span style="color: #09ace2; font-size: 15px"><strong>#postname# </strong></span></span><br>
    <span class="btn-info btn-xs">2</span> 本文章地址:<font color="#09ace2">#url# </font><br>
    <span class="btn-info btn-xs">3</span> 本网站的文章部分内容可能来源于网络,仅供大家学习与参考,如有侵权,请发送邮件至<font color="#09ace2">xxx@qq.com</font>进行删除处理。<br>
    <span class="btn-info btn-xs">4</span> 本站一切资源不代表本站立场,并不代表本站赞同其观点和对其真实性负责。<br>
    <span class="btn-info btn-xs">5</span> 如您发现本站提供资源链接失效或有违规现象,请联系我们处理。<br>
</fieldset>

推荐一款WordPress跳转插件

插件功能

WordPress外链跳转插件是果核团队开发的一款WordPress插件,能对文中外链添加一层过滤,有效防止追踪,以及提醒用户即将进入新的网站。类似于知乎、CSDN打开其他链接的提示。当然,你也可以设置白名单,这样进入一些网站就不会弹出提示。

插件截图:

图片[1]-新锐博客

插件设置

图片[2]-新锐博客

插件信息

下载地址

WordPress外链插件 - cp-link-open
❌