WordPress.org

Ready to get started?Download WordPress

Forums

127

Weather Hack (208 posts)

  1. Jeremiah
    Member
    Posted 10 years ago #

    I just got through cleaning up a weather module that was originally for mambo.
    It displays the current weather conditions for a specified station with a pretty icon.
    See it in action here: http://www.sonicpling.net
    With all options enabled: http://www.sonicpling.net/weather/weather-full.php
    Get the zip file here: http://www.sonicpling.net/weather/weather.zip
    there's a csv file included that list stations
    It doesn't validate. and I don't have time to fix it right now. I may later, but if someone wants to jump in and do that I'd be happy to update the zip file.
    Thanks,
    Jeremiah

  2. LoganSix
    Member
    Posted 10 years ago #

    I am using phpWeather on my site. http://www.dean-logan.com/
    Their last update was Feb. 02, 2004.
    It gets information from an airport station. Does yours use the same stations? phpWeather stations seem to update every 45 minutes, it would be nice to have a more frequent update. It uses a database to cache the station information, however, I have my settings set not to use the database, because it wouldn't update.
    I'll have to say, your cloud icons are nicer.

  3. Jeremiah
    Member
    Posted 10 years ago #

    Logan, I'm pretty sure it's not doing any caching at all. every time the page is loaded it fetches new info.
    I really would rather have the option to cache, but I don't have time to get that working right now.
    NM, I thought it looked pretty good as well, thats why I tried to get it working for wordpress! :-)
    I've never done anything with PHP before, but I have a little perl and javascript exp. so, while I'm not entirely lost, I guess I may as well be.. lol I think that the design will have to remove the alignment option in order to validate as XML.. is that correct? I'm wanting to say that you can't have the alignment specified within the content.
    Probably be better to just drop the table entirely and just flow the info in with br's and have it honor whatever alignment is set already in the sidebar.
    Just to be clear, I didn't write this originally, it was written for mambo (credit for the original author is in the file, I can't remember his name off the top of my head) I thought it looked nifty and the code looked clean, so I stripped all the mambo specific stuff out, cleaned it up a bit and posted it here.
    --Jeremiah

  4. NuclearMoose
    Member
    Posted 10 years ago #

    Jeremiah,
    There's certainly no need to keep the table structure. You could easily build it in a DIV and then create some styling with CSS. One thing about XHTML is that it is a lot fussier than HTML in that you have to tighten up some of the things you used to get a away with in plain HTML.
    Example, you have to "close" tags that once didn't have a closing part, as in the < br /> tag. Another is that you must order your tags correctly, as in this example:
    < em > < strong > Text goes here < /em > < /strong > is bad in XHTML.
    < em > < strong > Text goes here < /strong > < /em > is semantically correct.
    All kinds of little stuff like that.

  5. snark_goddess
    Member
    Posted 10 years ago #

    This is really nice! I don't have it up on my site right now, but I'll probably be adding it to one of my pages soon. Thanks! :)

  6. Jeremiah
    Member
    Posted 10 years ago #

    ok, I cleaned it up a little more and made it respect the wordpress stylesheet.
    Tables are gone. Also seems to validate now.
    new file is available here:
    http://www.sonicpling.net/weather/weather-new.zip
    Example:
    http://www.sonicpling.net
    Example with all options:
    http://www.sonicpling.net/weather/weather-full.php
    I used SPAN's to seperate the title and the info, e.g. "Temp" and "69f"
    you can access them in your stylesheet thus:
    .weather_title { font-weight: bold; }
    #weather { text-align: center; }
    #weather ul li { text-align: center; }
    (obviously, I have this flowing in as a LI in the menu UL)
    Comments?

  7. TechGnome
    Moderator
    Posted 10 years ago #

    That's sweet! I've got it up and running on my site now. It was so easy! I made a couple of minor changes to the code (I moved the icon pic out of the LI tag (the little dot was driving me nuts) and put the code in a function that I can then call (so I don't clutter my menu code. I think that about does it for the changes I made.
    TG

  8. Jeremiah
    Member
    Posted 10 years ago #

    TG, Glad you like it!
    this is how I am calling it in my index.php:
    <?php include(ABSPATH . 'weather/weather.php'); ?>
    is there a better way?
    --Jeremiah

  9. TechGnome
    Moderator
    Posted 10 years ago #

    Well, what I did was to put all of the what I call "loose" code (that would be any code that wasn't in a function already, and jsut runs when the file is included) into a function. I then used the my-hacks to include the file (which is what it's for). Then in my menu I call the function.
    Looks something like this:
    In my-hacks.php: <?php include_once("/weather.php");
    In menu.php: <?php show_wp_weather(); ?>
    There's an advantage to this method. Let's say I wanted to show the weather for different places, I could then add a parameter to the function and pass in the station code for each place I want to display. Or, let's say I add the ability to let the user set their location so their weather shows up. By having in the function, I can pass in a different code, and viola!
    It's really a minor thing, and as a developer, I like to have things encapsulated like that. Especially when it gives greater flexibility to the user of the code.
    TG

  10. NuclearMoose
    Member
    Posted 10 years ago #

    Has this weather hack been documented in the Wiki? :)

  11. Jeremiah
    Member
    Posted 10 years ago #

    That sounds pretty nifty TG..
    I had originally wanted to use the my-hacks.php and just output the $weather bit in the page, but hadn't gotten that far. Your solution sounds nicer.
    do you want to put that up in the wiki? I tried the other day to log in, and couldn't.
    Doesn't taking the image out of the LI break the logical flow of the code? for screen readers and such?
    I didn't like the bullet either, but I thought it should stay inside the UL, so I just styled it out.
    Thanks,
    Jeremiah

  12. TechGnome
    Moderator
    Posted 10 years ago #

    No, it doesn't break the layout at all.
    what it ends up looking like is this:
    the UL has the title "Weather For Station XYZ" a break, and then the image. Then the UL follows, with each detail item in LI tags.
    TG

  13. Anonymous
    Unregistered
    Posted 10 years ago #

    TG - I tried your method in my-hacks.php, but that makes it display the results of weather.php after it is parsed and I can't navigate through my wp admin page at all! Am I missing something when implementing that code?

  14. TechGnome
    Moderator
    Posted 10 years ago #

    Ummm.... ?? I dunno.... can you make a text copy of your weather.php file so I can take a look..... wait... better yet, let me supply a link to my copy.
    Gimmie a few.
    TG

  15. TechGnome
    Moderator
    Posted 10 years ago #

    OK, I posted my copy of weather.php right here.
    I have an hard coded hr tag in there that you might want to take out, otherwise it's good to go.
    I dumped it (and all of the files from the original download) into a folder called wp-weather. Then in my-hacks.php, I have the line include_once('wp-weather/weather.php');
    In my menu, I call the weather function like this:
    <?php show_wp_weather(); ?>
    And that's all I did.
    TG

  16. Aubrey (@starshaped)
    Member
    Posted 10 years ago #

    Yeah, mine looks like that. Would you want to use include_once and not require_once? I should try require_once to see if that does what I want it to do, as include_once makes it display on all my admin pages.

  17. TechGnome
    Moderator
    Posted 10 years ago #

    Um.... I think something got missed.... In the weather.php file, there is an echo $weather at the bottom, very last line..... take that out.... the echo should up in the show_wp_weather() function......
    TG

  18. Strokemouth
    Member
    Posted 10 years ago #

    Love this hack. :)
    One question though, the conditions are being out put like this:
    _TEMPERATURE 28°F
    _CONDITION _MIST
    Is there something I'm missing, or is this handled in the CSS or something?
    You can see it in action at my WIP page: http://www.flatlip.com/wordpress

  19. TechGnome
    Moderator
    Posted 10 years ago #

    Yeah, Um also down load the zip for the FIRST post in this thread, it has a language.php file that was left out of the latest version. I found that out the hard way as well.
    TG

  20. Aubrey (@starshaped)
    Member
    Posted 10 years ago #

    Yeah, that probably did it... I am on crack this week. Thanks! :)

  21. Strokemouth
    Member
    Posted 10 years ago #

    Thanks TG, I knew PEBKAC. :)
    Hack works beautifully now.

  22. mamabean
    Member
    Posted 10 years ago #

    Oh my, this was easy to set up! Thank you for this!!

  23. Jeremiah
    Member
    Posted 10 years ago #

    oops.. I'll fix that, and update the zip to include TG's modifications when I get home this evening..
    --Jeremiah

  24. flakkito
    Member
    Posted 10 years ago #

    Thanks for this hack, lots of hard work!
    I have one mod i'd like to make-
    how to remove border attribute from image?
    <img src='wp-weather/wicons/4cloud_norain.png' border='0'
    Thanks again
    :)

  25. Anonymous
    Unregistered
    Posted 10 years ago #

    TG- thanks for the quick response!
    I tried both suggestions in my css but soon realized the "border" was being echoed from weather.php.
    I removed from there, and voila- validates xhtml 1.1!
    Thanks again,
    Rob

  26. flakkito
    Member
    Posted 10 years ago #

    Anon was me, forgot to log in...

  27. Jeremiah
    Member
    Posted 10 years ago #

    I wasn't getting a validation error on the border attribute, but I agree that it should be removed. I'll do that this evening as well. Thanks for pointing that out Flakkito!
    --Jeremiah

  28. TechGnome
    Moderator
    Posted 10 years ago #

    Jeremiah.... don't force the remove in the HTML (IE, don't se the border="0" in the img tag), let the CSS do that.... Some people may want it on, others may not.
    TG

  29. Anonymous
    Unregistered
    Posted 10 years ago #

    TG I was just going to remove the border attribute entirely.. then it should honor whateven you have set in the css for the other images on your blog.
    does that sound right?
    --Jeremiah

  30. Jeremiah
    Member
    Posted 10 years ago #

    Oops, forgot to login.. That last one was me.
    --Jeremiah

127

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.