Creat a special page for bing daily picture

Author: Calf  < https://www.calf.one >

As a php beginner, I donno how to write api, so just modify the wordpress code.

First: create a template of bing

Go to the current theme’s folder, copy page.php to bing.php, add below codes to file top:

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

find code “get_template_part(‘content’, ‘page’);” , change ‘page’ to ‘bing’.template-bing

Second : modify content codes

copy content-page.php to content-bing.php, delete the code “<?php the_content(); ?>” , and add below codes:

<?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

Last: Create a new page, select “bing” template, and publish, well done!

 

Reproduced this post please remake the source: 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!

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

    Reply
  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!

    Reply
  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..

    Reply
  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.

    Reply
  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!

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

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

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

    Τhanks!

    Reply
  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?

    Reply

Leave a comment

Your email address will not be published.


*


This site uses Akismet to reduce spam. Learn how your comment data is processed.

calf-blog-top