Kwebble : Blog

  • Putting the geo position in a Wordpress RSS feed

    Gepubliceerd op 2 oktober 2005 in Programming. 3 reacties

    The last few days I’ve been looking at adding geographic information to articles on this website. For WordPress, the software this site is running on, I found the Geo plugin with which you can store geographic coordinates for an article. The plugin adds this information to the page of each article, but not in the RSS feed, so I made a function that does this, though not automatically.

    To use it, start with adding the following function to the Geo plugin. I’m using version 1.0, don’t know if it works in earlier versions:

    /**
     * Returns the tags with geo information for inclusion in RSS 2.0 feeds.
     *
     * Include a call to this function inside the <item> tag to
     * add tags with geo information if available.
     * To keep the feed valid add these namespace declarations to the <rss> tag:
     *    xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
     *    xmlns:icbm="http://postneo.com/icbm"
     *    xmlns:geourl="http://geourl.org/rss/module/"
     */
    function get_the_rss_geotags() {
    	global $wp_query;
    
    	if(!get_settings('use_geo_positions')) return;
    
    	list($lat, $lon) = split(',', get_post_meta($wp_query->post->ID, '_geo_location', true));
    	if ($lat == '' || $lon == '') {
    		if (get_settings('use_default_geourl')){
    			// send the default here
    			$lat = get_settings('default_geourl_lat');
    			$lon = get_settings('default_geourl_lon');
    		}
    	}
    	if ($lat != '' && $lon != '') {
    		echo "<geo :lat>$lat</geo><geo :long>$lon</geo>\n"
    				. "<icbm :latitude>$lat</icbm><icbm :longitude>$lon</icbm>\n"
    				. "<geourl :longitude>$lon</geourl><geourl :latitude>$lat</geourl>\n";
    	}
    }
    

    Now you can add this line to wp-rss2.php, somewhere inside the <item> tag:

    <?php echo get_the_rss_geotags(); ?>
    

    Also remember to add these namespace declarations to the rss tag:

    <rss version=”2.0”
    	xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
    	xmlns:icbm="http://postneo.com/icbm"
    	xmlns:geourl="http://geourl.org/rss/module/">
    

    That’s it.

    • geocode
    • php
    • plugin
    • rss
    • wordpress

    3 Reacties

    1. Michael-John Turner 25-02-2006 (20:32)

      Avatar

      Great – thanks for the info! I see the latest version of Geo already includes get_the_rss_geotags(), but, natrually enough, I still needed to patch wp-rss2.php to include the geo and ICBM tags.

    2. Rob Schlüter 25-02-2006 (22:24)

      Avatar

      Nice to see that my function is now included in the current Geo plugin.

    3. Sameer 3-08-2006 (12:36)

      Avatar

      This is great. Thanks a lot!!

  • Rubrieken

    • Artikelen
    • Foto's
    • Links
    • Media
    • Overheid
    • Programming
  • Recente Berichten

    • Stanford Web Applications course lectures
    • The importance of knowing Unicode
    • “If you are not paying for it, you’re not the customer; you’re the product being sold.”
    • Inzage in je gegevens bij Facebook
    • Tuning Oracle UCM 11 & Site Studio performance
  • Gerelateerde berichten

    • Filter .svn folders in Eclipse Navigator
    • Astronomy picture of the day feed met grote foto’s
    • Simple Cloud API
    • Showing related articles in a WordPress blog
    • Don’t forget __isset() with overloaded setters and getters
  • Abonneren

    • Atom feed Artikelen
    • Atom feed Reacties
  • Archief

© Rob Schlüter - Contact