阅读视图

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

WordPress侧边栏添加欢迎语

前言

今天逛博客看到一个好玩的东西,分享给大家

参考

原地址:https://blog.shiguang666.eu.org/2024/10/25/479d38b5fc12/

教程

1.首先去青桔API申请key,目前我们使用到的API是完全免费且无次数限制的。

2.访问api接口:https://api.76.al/api/ip/query?key=your_key

3.将如下代码添加到WordPress小工具中的自定义html内

<div id="announcement-widget">
    <div class="card-widget card-ip-info">
        <div class="announcement_content">
            <div id="welcome-info" style="display: none;">
                <div class="loading-spinner"></div>
            </div>
        </div>
    </div>
</div>

<style>
    #welcome-info {
        display: flex;
        justify-content: center;
        align-items: center;
        height: auto;
    }
    .loading-spinner {
        width: 50px;
        height: 50px;
        border: 3px solid rgba(0, 0, 0, 0.1);
        border-radius: 50%;
        border-top: 3px solid #3498db;
        animation: spin 1s linear infinite;
    }
    @keyframes spin {
        0% { transform: rotate(0deg); }
        100% { transform: rotate(360deg); }
    }
</style>

<script>
    const createAnnouncementComponent = () => {
        const ipInfoElement = document.createElement('div');
        ipInfoElement.className = "card-widget card-ip-info";
        ipInfoElement.innerHTML = `
            <div class="announcement_content">
                <div id="welcome-info">
                    <div class="loading-spinner"></div>
                </div>
            </div>
        `;
        return ipInfoElement;
    };

    const fetchIpInfo = () => {
        fetch('https://api.76.al/api/ip/query?key=your_key')
            .then(response => response.ok ? response.json() : Promise.reject('Network response was not ok'))
            .then(data => showWelcome(data))
            .catch(() => showErrorMessage());
    };

    const getDistance = (e1, n1, e2, n2) => {
        const R = 6371; // Earth radius
        const toRadians = (degree) => degree * (Math.PI / 180);
        const a = Math.sin(toRadians(n1)) * Math.sin(toRadians(n2)) +
                  Math.cos(toRadians(n1)) * Math.cos(toRadians(n2)) *
                  Math.cos(toRadians(e1 - e2));
        return Math.round(R * Math.acos(a));
    };

    const showWelcome = (ipLocationData) => {
        if (!ipLocationData || !ipLocationData.data) {
            return showErrorMessage();
        }

        // 修改为你自己的经纬度 
            const myLng = 121.38206; //经度
            const myLat = 31.11325; //维度
        const { lng, lat, country, prov, city, district } = ipLocationData.data; // 获取区的信息
        const dist = getDistance(myLng, myLat, lng, lat);
        const pos = country === "中国" ? `${prov} ${city} ${district}` : `${city}, ${district}`; // 包含区的信息

        const welcomeInfoElement = document.getElementById("welcome-info");
        welcomeInfoElement.style.display = 'block';
        welcomeInfoElement.innerHTML = `
            💖 欢迎来自 <b><span style="color:#3390ff;">${pos}</span></b> 的朋友<br>
            📏 您距博主约 <b><span style="color: #3390ff;">${dist}</span></b> 公里<br>
        `;
    };

    const showErrorMessage = () => {
        const welcomeInfoElement = document.getElementById("welcome-info");
        welcomeInfoElement.style.display = 'block';
        welcomeInfoElement.innerHTML = `<p>获取IP信息失败,请检查网络.</p>`;
    };

    const initialize = () => {
        document.body.appendChild(createAnnouncementComponent());
        fetchIpInfo();
    };

    window.onload = initialize;
</script>

4.将其中的your_key改为你自己申请的key

5.访问api接口,将其中的lat和lng替换代码中的经纬度

// 修改为你自己的经纬度  
const myLng = 121.38206; //经度
const myLat = 31.11325; //维度

6.访问主页就可以看到了

网站使用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>

分享一个好看的404html页面

前言

网站新建的时候都会有默认的404页面,但是感觉那个不好看于是就自己找了个并且修改了一下代码

截图

图片[1]-新锐博客

代码

在网站根目录新建一个404.html文件,将如下代码放进去

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>404</title>
<style>
html,body{height:100vh}
html:before,html:after,body:before,body:after{content:'';background:linear-gradient(#203075,#233581);border-radius:50%;position:absolute;top:50%;left:50%;transform:translate(-50%,-50%)}
html:before,body:before{background:linear-gradient(#233581,#203075)}
html{background:linear-gradient(#203075,#233581);overflow:hidden}
html:before{height:105vmax;width:105vmax;z-index:-4}
html:after{height:80vmax;width:80vmax;z-index:-3}
body{display:flex;justify-content:center;align-items:center;color:#FFF;font-family:'Varela Round',Sans-serif;text-shadow:0 30px 10px rgba(0,0,0,0.15)}
body:before{height:60vmax;width:60vmax;z-index:-2}
body:after{height:40vmax;width:40vmax;z-index:-1}
.main{text-align:center;z-index:5}
p{font-size:18px;margin-top:0}
h1{font-size:145px;margin:0}
.countdown{font-size:24px;margin-top:20px}
.bubble{background:linear-gradient(#EC5DC1,#D61A6F);border-radius:50%;box-shadow:0 30px 15px rgba(0,0,0,0.15);position:absolute}
.bubble:before,.bubble:after{content:'';background:linear-gradient(#EC5DC1,#D61A6F);border-radius:50%;box-shadow:0 30px 15px rgba(0,0,0,0.15);position:absolute}
.bubble:nth-child(1){top:15vh;left:15vw;height:22vmin;width:22vmin}
.bubble:nth-child(1):before{width:13vmin;height:13vmin;bottom:-25vh;right:-10vmin}
.bubble:nth-child(2){top:20vh;left:38vw;height:10vmin;width:10vmin}
.bubble:nth-child(2):before{width:5vmin;height:5vmin;bottom:-10vh;left:-8vmin}
.bubble:nth-child(3){top:12vh;right:30vw;height:13vmin;width:13vmin}
.bubble:nth-child(3):before{width:3vmin;height:3vmin;bottom:-15vh;left:-18vmin;z-index:6}
.bubble:nth-child(4){top:25vh;right:18vw;height:18vmin;width:18vmin}
.bubble:nth-child(4):before{width:7vmin;height:7vmin;bottom:-10vmin;left:-15vmin}
.bubble:nth-child(5){top:60vh;right:18vw;height:28vmin;width:28vmin}
.bubble:nth-child(5):before{width:10vmin;height:10vmin;bottom:5vmin;left:-25vmin}
</style>
</head>
<body>
<div class="bubble"></div>
<div class="bubble"></div>
<div class="bubble"></div>
<div class="bubble"></div>
<div class="bubble"></div>
<div class="main">
<h1>404</h1>
<h2>您访问的页面不存在</h2>
<p class="countdown">页面将在 <span id="countdown">3</span> 秒后自动跳转到首页</p>
</div>

<script>
// 倒计时3秒后跳转到首页
let countdown = 3;
let countdownElement = document.getElementById('countdown');
let countdownInterval = setInterval(function() {
  countdown--;
  countdownElement.textContent = countdown;
  if (countdown <= 0) {
    clearInterval(countdownInterval);
    window.location.replace("/");
  }
}, 1000); // 每秒更新一次
</script>
</body>
</html>

 

Lsky-Pro - 一款多用户轻量级图床程序

前言

兰空图床可以帮您保管大量无处安放的图片,数据可以自由选择储存驱动,支持主流第三方储存。

作为一个助手,它不仅可以将您把图片以指定规则存放在指定位置,还有更多强大的功能来帮助您处理这些图片。

教程

1.首先PHP版本要≥8.0.2

2.安装好如下扩展和函数

  • BCMath PHP 扩展
  • Ctype PHP 扩展
  • DOM PHP 拓展
  • Fileinfo PHP 扩展
  • JSON PHP 扩展
  • Mbstring PHP 扩展
  • OpenSSL PHP 扩展
  • PDO PHP 扩展
  • Tokenizer PHP 扩展
  • XML PHP 扩展
  • Imagick 拓展
  • exec、shell_exec 函数
  • readlink、symlink 函数
  • putenv、getenv 函数

2.下载并且上传源码到根目录,设置网站运行目录为/public ,设置以下伪静态

location / {
  try_files $uri $uri/ /index.php?$query_string;
}

3.访问域名然后等待环境检测,点击下一步根据提示进行安装。

4.安装好后访问域名就可以使用了。

下载地址

Github:https://github.com/lsky-org/lsky-pro/releases

镜像站:https://hub.yzuu.cf/lsky-org/lsky-pro/releases

千万不要下载Source code 文件。

截图

前台

图片[1]-新锐博客

后台

图片[2]-新锐博客

 

给你的网站添加一个Ctrl+D收藏引导

前言

现在很多网站都有以下截图的Ctrl+D收藏的引导图片,这次就教大家如何用代码实现。

截图

图片[1]-新锐博客

教程

在 wp 后台打开外观 - 小工具,然后将下面代码用自定义 HTML 添加至底部小工具即可,如果是想在每一个页面都加上这个,就在主题根目录下的footer.php 文件里的末尾添加以下代码即可。

  • 默认是黑色的底色,如果不喜欢黑色底色可以替换 #18222b 颜色代码
  • 文本内容也可自己根据自己的需求来适当修改

代码

<style type="text/css">
#go-fav {
width: 100%;
height: 60px;
line-height: 60px;
text-align: center;
background: #18222b;
font-size: 14px;
font-weight: 400;
color: rgba(255, 255, 255, 1)
}
 
#go-fav span {
padding: 5px 10px;
background: rgba(255, 197, 0, 1);
border-radius: 5px;
color: #202020;
margin: 0 5px
}
 
#go-fav a {color: #aeaeae}
 
#go-fav a:hover {color: var(--focus-color)
}
</style>
<div id="go-fav"> 按 <span>Ctrl</span>+<span>D</span> 收藏本站 或 <a class="find-more" href="/" rel="nofollow noopener" target="_blank"> 发现更多 </a></div>

网站侧边栏添加公众号翻滚模块

前言

有些网站都有很好看的翻滚公众号图片,刚好看到六月是只猫有相关的教程,就抄一下,以下是教程

教程

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

<div class="textwidget custom-html-widget"><div class="qqg-card-widget" id="qqg-card-wechat" onclick="window.open('https://www.xrbk.cn');">
    <div id="qqg-flip-wrapper">
      <div id="qqg-flip-content">
      <div class="qqg-face"></div>
      <div class="qqg-back qqg-face"></div>
    </div></div></div></div>

CoreNext主题添加如下CSS代码到子主题中

/* wxgzh-card-shadow */
 .wx-card-widget {
  box-shadow: 0 8px 16px -4px #2c2d300c;
  background: #fff;
  border: 1px solid #e3e8f7;
  transition: 0.3s;
  border-radius: 12px;
  transition: 0.3s;
  position: relative;
  overflow: hidden;
  margin-top: 1rem;
  padding: 1rem 1.2rem;
}

/* wxgzh-fanzhuan */
#wx-flip-wrapper {
    position: relative;
    width: 235px;
    height: 110px;
    z-index: 1;
}

#wx-flip-content {
    width: 100%;
    height: 100%;
    -webkit-transform-style: preserve-3d;
    transform-style: preserve-3d;
    transition: cubic-bezier(0, 0, 0, 1.29) 0.3s;
}

#wx-flip-wrapper:hover #wx-flip-content {
    -webkit-transform: rotateY(180deg);
    transform: rotateY(180deg);
}

.wx-face {
    position: absolute;
    width: 100%;
    height: 100%;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    background: url(/wx_face.png) center center no-repeat;
    background-size: 100%;
}

.wx-back.wx-face {
    display: block;
    -webkit-transform: rotateY(180deg);
    transform: rotateY(180deg);
    box-sizing: border-box;
    background: url(wx_code.png) center center no-repeat;
    background-size: 100%;
}

/* wxgzh-background */
.wx-card-widget#wx-card-wechat::before {
    position: absolute;
    width: 100%;
    height: 100%;
    left: 0;
    top: 0;
    background: url(gzh_cover.png) center center no-repeat;
    content: '';
}

.wx-card-widget#wx-card-wechat {
    background: #57bd6a;
    display: flex;
    justify-content: center;
    align-content: center;
    padding: 0;
    cursor: pointer;
    border: none;
    height: 110px;
}

.wx-card-widget#wx-card-wechat img {
    max-height: 110px;
    object-fit: cover;
}

/* QQG-card-shadow */
 .qqg-card-widget {
  box-shadow: 0 8px 16px -4px #2c2d300c;
  background: #fff;
  border: 1px solid #e3e8f7;
  transition: 0.3s;
  border-radius: 12px;
  transition: 0.3s;
  position: relative;
  overflow: hidden;
  margin-top: 1rem;
  padding: 1rem 1.2rem;
}

/* QQG-fanzhuan */
#qqg-flip-wrapper {
    position: relative;
    width: 235px;
    height: 110px;
    z-index: 1;
}

#qqg-flip-content {
    width: 100%;
    height: 100%;
    -webkit-transform-style: preserve-3d;
    transform-style: preserve-3d;
    transition: cubic-bezier(0, 0, 0, 1.29) 0.3s;
}

#qqg-flip-wrapper:hover #qqg-flip-content {
    -webkit-transform: rotateY(180deg);
    transform: rotateY(180deg);
}

.qqg-face {
    position: absolute;
    width: 100%;
    height: 100%;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    background: url(/qqg_face.png) center center no-repeat;
    background-size: 100%;
}

.qqg-back.qqg-face {
    display: block;
    -webkit-transform: rotateY(180deg);
    transform: rotateY(180deg);
    box-sizing: border-box;
    background: url(/qqg_code.png) center center no-repeat;
    background-size: 100%;
}

/* QQG-background */
.qqg-card-widget#qqg-card-wechat::before {
    position: absolute;
    width: 100%;
    height: 100%;
    left: 0;
    top: 0;
    background: url(/qq_cover.png) center center no-repeat;
    content: '';
}

.qqg-card-widget#qqg-card-wechat {
    background: #00aef8;
    display: flex;
    justify-content: center;
    align-content: center;
    padding: 0;
    cursor: pointer;
    border: none;
    height: 110px;
}

.qqg-card-widget#qqg-card-wechat img {
    max-height: 110px;
    object-fit: cover;
}

下载附件图片素材上传到服务器,并修改css里面的url就行了,F5刷新就可以看到效果了。

网站翻转素材

记一次WordPress编辑器尝试和插件使用

前言

因为每日新闻图片版的有点问题,有时候文字不能显示,所以就想直接做个页面的文字版,接下来就是尝试中出错的过程。

过程

如上所说,我先去把图片里获取每日新闻的数据的代码搞出来,然后就想直接粘贴到WordPress的编辑器里。但是访问页面就发现显示的是代码不是效果。

然后一查才发现WordPress编辑器里不能执行PHP代码只能执行HTML代码。然后就开始钻牛角尖了,各种尝试,通过其他AI编程或者百度等方式查询到php可以在html里执行。

我就开始了html和php结合的方法,但是发现代码一放到宝塔面板的网站目录下的html中就报错,放到WordPress编辑器里也一样,所以我就去查了下,发现html执行php代码需要php环境还有文件格式是php,那就回到了起点,这就让我很纠结,怎么让php代码在WordPress编辑器里运行?

突然想到了调用,比如在function.php里加调用或者插件,于是就倒腾了一下写了个获取当天星期几的图片和热榜数据的接口,然后再搞了个插件的php文件放到WordPress的插件目录下,最后到页面中调用就行了,经过AI编程和自己的理解最终成就了新的每日新闻界面。

这样每天访问这个界面就是不同的新闻信息了。

结语

最终虽然实现了效果但是倒腾了很久,不过还是有点成就感的。以后有时间的话还是多学习学习还是很重要的。

 

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>
❌