《每天60秒读懂世界自动更新》教程分享

图片[1] | 《每天60秒读懂世界自动更新》教程分享 | 无聊笔记

前言

添加这个每日60S有三种方法,一种是用官方接口获取文章,另一种则是直接用接口图片,还有一种通过第三方接口获取文字版内容。接下来我把这三种方法分享一下,不担保接口会失效,后期失效了可以自己网站找一下接口。

方法一

在全局js文件里添加这个代码就行了,子比主题用户直接放到主题的自定义JS代码下

//每日60秒
var str='https://api.03c3.cn/zb/api.php';
$.getJSON(str, function(json){
  var imgid = json.imageUrl;
  document.getElementById("suolue").src=imgid;
});

添加完js代码后,接下来新建文章或者页面添加以下代码发布即可!

<img id="suolue">

方法二

将下面的代码添加到../wp-content/themes/zibll目录下的functions.php中

function ttsistens(){//60s
  $sixs = json_decode(file_get_contents("https://www.zhihu.com/api/v4/columns/c_1261258401923026944/items"),true)['data'][0]['content'];
  return $sixs;
};

在../wp-content/themes/zibll/pages下新建ttsixs.php复制以下代码保存即可(部分数据自行修改)

接下来新建页面选择 (WL – 60S) 模板保存即可

方法三

例1:和方法2差不多,在../wp-content/themes/zibll/pages下新建一个xxx.php复制以下代码保存即可(部分数据自行修改),新建页面选择 (每日早报文字版) 模板保存即可

例2:纯页面代码,保存为***.php即可

<?php
$JsonText = file_get_contents('你的接口地址');
$Json = json_decode($JsonText,true);
$headImg = $Json['data']['head_image'];
$news = array_pad($Json['data']['news'],16,$Json['data']['weiyu']);
$width = 1000;
?>
<!DOCTYPE HTML>
<html>
    <head>
        <title>每日早报</title>
        <meta charset="UTF-8">
        <style>
            * {
                padding: 0px;
                margin: 0px;
            }
            body {
                margin:auto;
                width: <?php echo($width);?>px;
            }
            .box {
                padding: 25px;
                margin: 25px;
                border: 3px solid #CAB6AB;
            }
            hr {
                width: <?php echo($width - 100);?>px;
            }
            @font-face {
                font-family: Genshin;
                src: url('./Genshin.ttf');
            }
            .box p {
                font-family: Genshin;
                margin: 22px;
                font-size: 37px;
            }
            .title {
                font-family: Genshin;
                font-size: 55px;
                color: red;
                text-align: center;
                font-weight: 0;
                margin: 18px;
            }
        </style>
        <script>
            function updateTime() {
                var now = new Date();
                var hours = now.getHours();
                var minutes = now.getMinutes();
                var seconds = now.getSeconds();
                hours = (hours < 10 ? "0" : "") + hours;
                minutes = (minutes < 10 ? "0" : "") + minutes;
                seconds = (seconds < 10 ? "0" : "") + seconds;
                var timeString = hours + ":" + minutes + ":" + seconds;
               document.getElementById("currentTime").textContent = timeString;
            }
            setInterval(updateTime, 1000);
        </script>
    </head>
    <body>
        <div class="box">
            <img src="<?php echo($headImg);?>">
            <hr style="height:6px;background-color:#000;"/>
            <div class="title">每日60秒看世界</div>
            <p style="font-size:27px;text-align:right;float:right;display:inline-block;margin:0px;" id="currentTime"><?php echo date('H:i:s'); ?></p>
            <p style="font-size:27px;text-align:left;float:left;display:inline-block;margin:0px;"><?php echo($Json['data']['date']);?></p>
            <hr style="height:3px;background-color:#000;"/>
            <br/>
<?php
foreach ($news as $new) {
    echo "            <p>".$new."</p><br/>".PHP_EOL;
}
?>
            <p style="text-align:center;color:red;">无聊笔记</p>
        </div>
    </body>
</html>

接口可以去ALAPI申请,格式:https://v2.alapi.cn/api/zaobao?token=用户中心获取token&format=json

© 版权声明
THE END
喜欢就支持一下吧
点赞15 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容