WordPress.org

Plugin Directory

wiki:GetWeather

GetWeather

A plugin for getting and displaying the current weather conditions in any given locale. GetWeather is very simple to use, but can return a range of data.

A plugin by Jeff

Download

Instructions

  1. Change the config variables below in the "EDIT THIS" section
    (You may want to use the weather icons, in which case you should upload them to your server as well.)
  2. Upload this plugin to your wp-plugins/ directory
  3. Activate the GetWeather Plugin via the admin menu
  4. Place this code in your template:

<ul><?php get_weather('94115') ?></ul>

Or get much more fancier and include:

<ul><?php get_weather('94115', 'SF, CA', 'icon,temp,high,low') ?></ul>

You need only change the "citycode" (the first variable in the function) to your own city. You may use a US zip code or a standard city code. International users will have to use a standard city code.

Finding Your City Ouside the U.S.

  1. Go to the weather.com site
  2. Search for your city. (Example: "quebec")
  3. When you get to the page listing your current weather conditions, the url will look something like this: http://www.weather.com/outlook/travel/businesstraveler/local/CAXX0385?from=search_city
  4. The "City Code" is the string after "local/" and before "?". (In this case, "CAXX0385")
  5. You may use this code in place of a zip code when you live outside the U.S.

Extra Functionality

<?php get_weather($citycode, $title, $options) ?>

$citycode

A required attribute to define what city you want weather from

$title

If using the attribute "desc", this string will replace the default city name.

$options

A list of what attributes you want the plugin to return, and in what order to return them in.

Currently, you can include these things in your list of options (in any order, too):

  • desc - descriptiong - either the default, or one you define
  • icon - display the weather icon
  • temp - temperature
  • forecast - text description of current conditions
  • curtime - current time (or last weather update time)
  • sunrise - sunrise for today
  • sunset - sunset for today
  • vis - visible distance
  • wind - wind speed
  • hum - humidity
  • dew - dew point
  • high - high temperature
  • low - low temperature
  • sunset-sunrise - sunset/rise as one item
  • high-low - High and low as one item

Simple-cache

One of the major downsides of doing this kind of script is its reliance on another server during the page generation. Specifically, this single plugin can cause your "page created in" time to jump up 1-10 seconds.

In order to combat this, I created a simple little plugin called "simple-cache.php" which does pretty much what its name implies: simple caching. If you want to use this with GetWeather, it's pretty easy:

  1. Download simple-cache.php
  2. Upload simple-cache.php to your wp-content/plugins/ folder.
  3. Create a folder called "simple-cache" in wp-content/
  4. CHMOD 666 the simple-cache folder.
  5. Activate the plugin in your admin interface.

All done. The plugin defaults to refereshing stored content every 15 minutes, which should be fine for a weather plugin.

Last modified 9 years ago Last modified on 06/08/05 00:01:08