WordPress Weather Widget
Number 5 in Widget-A-Day is a Weather widget.
It isn't too fanciful. It displays the current condition, temperature, and the feels like temperature. It uses weather.com's xoap api to retrieve the information. I'll probably come back to this and make it better.
SVN Checkout
svn co http://svn.wp-plugins.org/weather-widget/trunk
Default display:

Admin panel:

Requirements
- WordPress 2.2 or 2.0.x/2.1.x with WordPress Widgets
- PHP 4.3.0 or greater (needed for function file_get_contents)
Installation
- Download weather.zip
- Extract and upload weather.php to the plugins/ directory
- Enable Weather Widget in the Plugin admin panel
- In widget admin panel, place Weather in the sidebar, and edit it to enter your location
Location
The location can either be a zip code for US users or the locid. To find the locid, you can do a search using http://xoap.weather.com/search/search?where=[search parameters].This will return an XML file with search results and their corresponding locid's.
You can also find it out by the Weather.com website. After searching for and selecting you city, you will be sent to a url that will look something like, http://www.weather.com/outlook/driving/interstate/local/USTX0617?from=search_city, where USTX0617 is the locid.
Image Hosting
I've provided the images used and provided by weather.com here. If you want to host your own images, extract and upload the files, then, in the admin panel, edit the 'Image Location' field to point to your directory of images. Make sure to have the trailing slash.
If you don't use your own images, you are free to use the ones that I've hosted, which are located at http://ja.meswilson.com/blog/weatherimages/
Editting display
You can edit 'Widget Formatting' to change how the info is displayed. To access the variables, use this formatting:
- %loc% – Location
- %temp% – Current temperature
- %feels% – Feels like temperature
- %icon% – The icon referring to the current weather. This is just a number
- %iconhref% – The location of the image with your set image location at the front
- %attribution% – The link supposedly required to be displayed. Weather data provided by weather.com®
The default formatting is:
<img src="%iconhref%" alt="%cond%" style="float:right;" />
%loc%<br />
<span style="font-size: 150%;">%temp% °F</span>
(%feels% °F)<br />
<span style="font-size: 65%; float: right;">%attribution%</a>
I just keep getting a blank screen after I include the the non-plugin version in my header. I works fine when it's on it's own page. Any suggestions?
i like the look of this plugin but i cant get it to work with my city
this is where i'm at Temecula CA
& i input all the info & it ends up showing some other city
i have tryed eveything
i'm going to have to go with wp-weather
i'm sure this one will work
Hi there: Thanks for the great widget.
I would like to add several weather locations but the widget can just only be published once on my wordpress blog, what can I do?
Hi James,
I am unable to extract the images as they are in gzip format and I'm using Windows Vista.
Can you provide me the same in zip file?
Thanks
Vinod
http://ja.meswilson.com/blog/weatherimages.zip
Thanks for the help James.
Is it possible to add some extra data for this widget? Such as tomorrow's or next days weather?
Hi James,
Just curious if I can modify the display city- weather.com displays my city as Midway Airport based on the zipcode when I really would like the location to display River Forest (a town about 10 miles from the airport it's displaying). Can I manually change the city? Thanks!
You can change it in display.
Hi James
I installed your plugin, love it. Just one thing, I dont know if it has been mentioned before, but when I set the locid to my hometown (ie. UKXX0282 ) it shows the nearest observation station, and not the hometown. Its easy enough to change, you just replace:
$start = strpos($cc,"") + 6;
$loc = substr($cc, $start, strpos($cc, "") – $start);
with
// $start = strpos($cc,"") + 6;
// $loc = substr($cc, $start, strpos($cc, "") – $start);
$placenamestart = strpos($data,"")+6;
$loc = substr($data, $placenamestart, strpos($data, "") – $placenamestart);
Hope this helps someone.
Steve
lol, wordpress is stripping the tags out automatically.
the 2 lines starting // contain the obst tags and the 2 replacement lines contain the dnam tag.
Clear as mud. Sorry.
@Steve, you can also just change %loc% to your location by hand in the formatting section.
I'll look at it a bit more to see whats up with it. This might be newer behavior from the API.
creating a website for a client. Not sure what happened, but weather temp will not show up. Uninstalled it and re-installed it several times. Dug into phpadmin to find where zip was being cashed. Deleted those lines of database, (I believe.) Not sure what is going on. Any ideas or help would be most appreciated.
http://www.rogersgrain.com/rogers
Thanks so much.
I second Omar's request for multiple location use of this widget. Can anyone give any hints or help? I tried creating separate directories and then using James' php code (provided in earlier posts, the one to put in non-wp sites) to call it, but to no avail. Any help is appreciated, thanks!
@Jason, could be file_get_contents problem. Try switching to cURL.
@lisa, there's been a lot of interest in multi-instance support. I just don't have the time to work on something that makes me no money right now.
Hi James, I want to thank you for this Plug in, It worked very good in my website, thanks and keep the good job.
Thank you very much for this widget! With a little template tweaking it's exactly what the majority of all bloggers want for a widget on their blogs.
Just to let everyone else out there know; don't feel bad about ripping off weather.com's attribution link… Those bastards now make you sit through a DOZEN click-out-of-many-opt-in-'speacials' just to get the xml weather feed… On top of asking you 1,001 personal questions and getting you to join their list!
I feel about as bad for removing their attribute link as I did when they shot Hitler.
Nice job, works well. Can I make the (clouds, etc, ) icons a little larger. I suppose I could upload new images.
I will answer my own own question. I just made the following change:
%loc%%temp% °F (%feels% °F)%attribution%
Last post code got screwed up. Ad this:
height:48px; width:48px;
Charles, I think Hitler shot himself, but I get what you're saying.
James, I just installed Wordpress 2.8, and I can't edit the widget format field. I used the widget successfully in 2.7.1, so maybe this is a new problem with 2.8?
Nevermind, I just can't click in the format field and then type. If I tab to the field, it allows me to type.
Hi James,
I was wondering if the plugin can be modified to work with multiple instances on one site as introduced in WP 2.8.
At this point it doesn't show up among the available plugins once deployed in a sidebar.