Bing搜索的首页每天都会推送一张很漂亮的图片,可以把它保存下来,当做电脑桌面或是自己的网站背景图。

这是今天的必应首页图

修瑶Bing每日图片壁纸

原理:

主要是使用必应每日图片的API获取参数来实现

http://cn.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1

使用:

直接利用PHP代码
将下面的代码复制到PHP中,上传到自己的服务器或者空间中就行

<?php
$str = file_get_contents('http://cn.bing.com/HPImageArchive.aspx?idx=0&n=1');   //从bing获取数据
if(preg_match("/<url>(.+?)<\/url>/ies",$str,$matches)){ //正则匹配抓取图片url
    $imgurl='http://cn.bing.com'.$matches[1];
}else{  //如果由于某些原因,没抓取到图片地址
    $imgurl='http://img.infinitynewtab.com/InfinityWallpaper/2_14.jpg'; //使用默认的图像(默认图像链接可修改为自己的)
}
header("Location: $imgurl");    //header跳转
?>

演示:

api.xiuyao.me/bing

接口:

修瑶提供2个接口一个高清1920一个标准1366

https://www.xiuyao.org/bing/1366t.php
https://www.xiuyao.org/bing/1920t.php

插入wordpress当登录页背景

将下面代码放入主题文件夹中的functions文件即可

/**
 * 修瑶自定义必应壁纸为登录页面背景
 * https://www.xiuyao.org/110.html
 */
function custom_login_head(){
$imgurl = 'https://api.xiuyao.me/bing/1920.php';
if($imgurl){
    echo'
'; }} add_action('login_head', 'custom_login_head'); add_filter('login_headerurl', create_function(false,"return get_bloginfo('url');")); add_filter('login_headertitle', create_function(false,"return get_bloginfo('name');"));

作为其它页面背景

同样使用两个API接口(推荐使用大的),补充CSS部分,如何让背景图固定不随滚动条滚动。

background:fixed;

为你背景图所在的选择器内,添加上面这句声明即可。


一个简简单单的90后小伙