Viewing 2 replies - 1 through 2 (of 2 total)
  • snomo

    Did you ever find a solution to this using Weather Underground? We have the same needs on our end.

    If you didn’t use Weather Underground, what did you use in order to get post/page weather specific on you site?

    Thanks.

    I’m working on a similar situation that may be of some use, I have towns set as a custom taxonomy term.

    Basically you have to create a custom function and hook it into your theme where you want it to display: (I’m using Genesis)

    //* Output location specific weather
    add_action('genesis_before_content','my_localized_weather');
    function my_localized_weather(){
    if(has_term( 'seattle', 'local-info' )){ //checks if seattle is in my local-info taxonomy.
    	$town = 'Seattle';
    echo do_shortcode("[wunderground location='$town, WA' numdays='3' layout='simple']"); //All the towns will be in WA so I don't need to modify the state.
    }
    }
    //This function will only work for one city, so it will need modification to work for all cities that I want to check, but it is a starting point.

    So, if you want to use a custom field you would have to check the meta, and dynamically set a string in the shortcode… something like this (untested):

    add_action('your_theme_hook','my_localized_weather');
    function my_localized_weather(){
    $my_city = get_post_meta($post->ID, 'city-field', true); //if your meta field is called: city-field
        if ( ! empty ( $my_city ) ) {
       echo do_shortcode("[wunderground location='$my_city, WA' numdays='3' layout='simple']");
    //as long as $my_city has your city this will work.
    //if your state is WA, otherwise run another meta check to pull in the state name.
    
    }
    }
Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Localizing to Post Locations’ is closed to new replies.