WordPress建立bing今日美图专门页面

作者:Calf < https://www.calf.one >

作为一个php新手,不会写api接口调用bing的首页图片,只好自己修改wordpress。

一、建立bing模板:

进入wordpress当前主题目录,复制一份page.php到bing.php,修改bing.php,在文件最前面添加模板信息代码:

<?php
/*
Template Name: Bing
*/
?>

找到get_template_part(‘content’, ‘page’);这段代码,将第二个参数’page’改为’bing’。

template-bing

 

二、修改页面内容代码:

复制一份content-page.php到content-bing.php,修改content-bing.php,删掉<?php the_content(); ?>这段代码,加入获取图片以及图片信息代码:

<?php
$str = file_get_contents(‘http://cn.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&mkt=zh-CN’);
$array = json_decode($str);
$imginfo = $array->{“images”}[0]->{“copyright”}.’ – Calf Blog’;
echo ‘<h3>’.$imginfo.'</h3>’
?>
<?php
$str = file_get_contents(‘http://cn.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&mkt=zh-CN’);
$array = json_decode($str);
$imgurl = ‘https://www.bing.com’.$array->{“images”}[0]->{“urlbase”}.’_1920x1080.jpg’;
echo ‘<a href=”‘.$imgurl.'”><img src=”‘.$imgurl.'”></a>’
?>

content-bing

三、接下来新建一个页面,模板选择名为“bing”的模板,发布即可。

 

转载请注明来源:https://www.calf.one

Readers Comments (10)

  1. Everything is very open with a clear clarification of the
    challenges. It was truly informative. Your site is very useful.
    Thanks for sharing!

    回复
  2. This text is worth everyone’s attention. When can I find out more?

    回复
  3. Hello there, I found your web site by the use of
    Google while searching for a similar matter, your web site came up, it seems good.
    I’ve bookmarked it in my google bookmarks.
    Hello there, just changed into alert to your blog through
    Google, and located that it’s truly informative. I am going to watch out for brussels.
    I’ll be grateful for those who continue this in future.
    Many people can be benefited from your writing.
    Cheers!

    回复
  4. I am extremely impressed with your writing talents and also with the structure in your blog.
    Is that this a paid theme or did you modify it yourself?
    Either way stay up the excellent quality writing, it’s rare to peer a great blog like this one nowadays..

    回复
  5. To improve your health club experience, what about considering taking with the someone you care about or maybe your partner, so that you can both take advantage of the therapeutic spa experience and both feel
    refreshingly revitalised. Do this process constantly, and you may turn into a goal achieving
    machine. As with any physical treatments, remember to be treated by way of a recognised professional practitioner that will discuss all of your required needs,
    plus highlight any medical or health issues you suffer from before commencing one of the treatments.

    回复
  6. I do not even understand how I stopped up right here, however I thought this put
    up used to be great. I don’t realize who you are but certainly you are going to a famous blogger in the event you aren’t already.
    Cheers!

    回复
  7. Fine way of explaining, and pleasant article to get information about my presentation subject matter, which i am going
    to present in academy.

    回复
  8. Only wanna comment on few general things, The website design and style is perfect, the written content is rattling great :D.

    回复
  9. Doess anyⲟne know if VaporFi (http://www.vaporfi.com [email protected]) sell Cannabinoid?

    Τhanks!

    回复
  10. Amazing things here. I am very happy to look your article.
    Thanks so much and I’m having a look forward to contact you.
    Will you please drop me a mail?

    回复

Leave a comment

Your email address will not be published.


*


此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据

calf-blog-top