lolitaloco

google weather snippet (wordpress)

Apr 5th, 2012
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.72 KB | None | 0 0
  1. function weatherWidget($place) {           
  2.     //delete_transient('weatherWidget');       
  3.     $transient = 'weatherWidget';
  4.     $weather = get_transient($transient);      
  5.     if(false === $weather) {
  6.         $weather = json_decode(json_encode((array) simplexml_load_file('http://www.google.com/ig/api?weather='.$place)),1);
  7.         set_transient($transient, $weather, 60 * 60 * 1); // clear cache every 60 minutes
  8.     }              
  9.     $temp_c = $weather['weather']['current_conditions']['temp_c']['@attributes']['data'];
  10.     $base = get_template_directory_uri().'/library/images';
  11.     $icon = $base.$weather['weather']['current_conditions']['icon']['@attributes']['data'];    
  12.     echo "<span class='temp'>$temp_c &deg;</span><img src='$icon' alt='weather'>"; 
  13. }   // end weatherWidget
Add Comment
Please, Sign In to add comment