网页添加背景图片的功能其实非常简单,这里分享两种方式:一种是添加自定义的图片作为背景、另一种是添加bing的每日图片作为背景。
第一种添加自定义的图片作为背景,只需要添加如下代码到header文件的</head>标签内:
<style>body {background-image: url("图片地址,本博客使用的是{$host}zb_users/theme/{$theme}/image/background.png");background-position:left top;background-size:auto;background-repeat:repeat;background-attachment:scroll;}</style>
第二种添加bing的每日图片作为背景,需要如下几步即可实现:
(1)使用 notepad++ 或者其他专业的网页编辑器新建一个包含以下内容的 php 文件,如命名为 bing.php 文件。
<?php$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];}if($imgurl){header('Content-Type: image/JPEG');@ob_end_cl