WordPress教程 · WPtech

WordPress 使用必应(Bing)美图作为后台登录背景

小编 · 10月19日 · 2019年 ·

bing 必应今日美图还是很不错的,非常漂亮,又没有水印,家里 win10 系统的待机背景图也可以,但是一直没找到如何调用出来,谷歌了一下 bing 必应今日美图可以调用。Bing 必应风景美图可谓一大特色,大自然是一个神奇的魔术师,把世界万物变得五颜六色。翠绿的山林,倾泻而下的瀑布,瑰丽丰富的海底世界,云雾缭绕的日出,巧夺天工的峭壁,蔚蓝宽广的大海,闪现的彩虹……它们都是自然赋予我们的财富!喜欢就不要错过咯!最重要的是它的背景图每天都在自动更换哦~~~

WordPress 使用必应(Bing)美图作为后台登录背景

实现方法一:

将以下代码加入至主题目录 Functions.php 文件最后面?>标签前(如果没有?>标签,则直接加到最后面)保存(1366*768 分辨率):

//调用bing美图作为登录页背景图
function custom_login_head(){
$str=file_get_contents('http://cn.bing.com/HPImageArchive.aspx?idx=0&n=1');
if(preg_match("/<url>(.+?)<\/url>/ies",$str,$matches)){
$imgurl='http://cn.bing.com'.$matches[1];
    echo'<style type="text/css">body{background: url('.$imgurl.');width:100%;height:100%;background-image:url('.$imgurl.');-moz-background-size: 100% 100%;-o-background-size: 100% 100%;-webkit-background-size: 100% 100%;background-size: 100% 100%;-moz-border-image: url('.$imgurl.') 0;background-repeat:no-repeat;background-image:none;}</style>';
}}
add_action('login_head', 'custom_login_head');

实现方法二:

能够获取到必应每日高清美图接口(1920*1080 分辨率):

/**自定义登录界面背景*/
//调用bing美图作为登录页背景图
function custom_login_head(){
    $str=file_get_contents('http://cn.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1');
    if (preg_match("/\/(.+?).jpg/", $str, $matches)) {
        $imgurl='http://s.cn.bing.net'.$matches[0];
    }
    echo'<style type="text/css">body{background: url('.$imgurl.');background-image:url('.$imgurl.');-moz-border-image: url('.$imgurl.');}</style>';
    //这里我对background图片的样式进行了调整
    //方便小分辨率屏幕(如手机)显示图片正常,否则会被压缩
}
add_action('login_head', 'custom_login_head');

将以上代码加入至主题目录 Functions.php 文件最后面?>标签前(如果没有?>标签,则直接加到最后面)保存,wordpress 登录界面背景就会每日更新为必应美图啦。

实现方法三:

By the way,顺便提供一个获取高清原图的 php 源码:

<?php
    $str=file_get_contents('http://cn.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1');
if (preg_match("/\/(.+?).jpg/", $str, $matches)) {
    $imgurl='http://s.cn.bing.net'.$matches[0];
}
if ($imgurl) {
    header('Content-Type: image/JPEG');
    @ob_end_clean();
    @readfile($imgurl);
    @flush();
    @ob_flush();
    exit();
} else {
    exit('error');
}
?>
0 条回应

必须 注册 为本站用户, 登录 后才可以发表评论!