Don't like ads? PRO users don't see any ads ;-)
Guest

wallpaper.php

By: a guest on Jun 30th, 2012  |  syntax: None  |  size: 1.42 KB  |  hits: 198  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <form action="" method='POST'>
  2.     <input type="text" name="keyword" placeholder="keyword" />
  3.     <button name='submit' value="submit">Submit</button>
  4. </form>
  5.  
  6. <?php
  7. if($_POST['submit'])
  8. {
  9.  
  10.         $query = $_POST['keyword'];
  11.         $query = str_replace(' ','%20',$query);
  12.         $url = "http://api.bing.net/json.aspx?AppId=01B352A888B29AE34D58B17E7C1317F9317F2714&Query=$query&Sources=image";
  13.        
  14.         $wallpaper = file_get_contents($url);
  15.         $wallpaper = json_decode($wallpaper);
  16.         $wallpaper = $wallpaper->SearchResponse->Image;
  17.        
  18.            
  19.         $posttitle = $wallpaper->Results;
  20.         $posttitle = $posttitle[0];
  21.         $posttitle = $posttitle->Title;
  22.        
  23.         $content = '';
  24.         foreach($wallpaper->Results as $item)
  25.         {
  26.                 $title = $item->Title ;
  27.                 $url = $item->MediaUrl;
  28.        
  29.                 $content .= "<img src='$url' />" . "<br />";
  30.                 $content .= $title . "<br />";
  31.                 $content .= $item->Width ." x ". $item->Height . " px";
  32.                
  33.         }
  34.        
  35.         // mulai mengenal fungsi insert post
  36.        $my_post = array(
  37.                         'post_title' => $posttitle,
  38.                         'post_content' => $content,
  39.                         'post_status' => 'publish',
  40.                         'post_author' => 1,
  41.                 );
  42.         wp_insert_post( $my_post );
  43.        
  44.  
  45. }
  46. ?>