<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Marty Spellerberg &#187; WordPress</title>
	<atom:link href="http://martyspellerberg.com/tag/wordpress/feed/" rel="self" type="application/rss+xml" />
	<link>http://martyspellerberg.com</link>
	<description>I provide online strategy and implementation to artists and institutions.</description>
	<lastBuildDate>Wed, 16 May 2012 18:13:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Address Geocoder &#8212; Simple WordPress Plugin</title>
		<link>http://martyspellerberg.com/address-geocode-wordpress-plugin/</link>
		<comments>http://martyspellerberg.com/address-geocode-wordpress-plugin/#comments</comments>
		<pubDate>Fri, 11 May 2012 14:43:22 +0000</pubDate>
		<dc:creator>Marty Spellerberg</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Google Maps]]></category>
		<category><![CDATA[Plugin]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://martyspellerberg.com/?p=1715</guid>
		<description><![CDATA[A simple WordPress plugin for saving location data with Posts and Pages. Conveniently converts addresses to lat/lng from the Edit screen. Storing addresses as lat/lng (rather than geocoding each time a user requests a page) decreases load time. This plug-in makes it easy for content managers to generate lat/lng, which is stored with the post [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://martyspellerberg.com/files/2012/06/geocoder-screenshot.jpg" alt="" title="" width="700" height="210" class="alignnone size-full wp-image-1750" /></p>
<p>A simple WordPress plugin for saving location data with Posts and Pages. Conveniently converts addresses to lat/lng from the Edit screen.</p>
<p>Storing addresses as lat/lng (rather than geocoding each time a user requests a page) decreases load time. This plug-in makes it easy for content managers to generate lat/lng, which is stored with the post as a custom field that can be accessed as part of the loop.</p>
<p>Uses the Google Maps JavaScript API V.3.</p>
<h3 style="clear: none">Installation and Usage</h3>
<ol>
<li>Get a copy of the plugin from <a href="http://wordpress.org/extend/plugins/address-geocoder/" class="external">WordPress.org</a> or <a  class="external" href="https://github.com/halfempty/address-geocoder/">Github</a>);</li>
<li>Unzip and upload it to your /plugins directory;</li>
<li>Activate the plugin from the Dashboard;</li>
<li>You should now find a metabox labeled &#8220;Geocoder&#8221; on your Post and Page Edit screens. Enter an address in the address field (this can be an exact address or the name of a famous place &#8212; anything Google will understand);</li>
<li>Press the &#8220;Geocode Address&#8221; button;</li>
<li>The Lat/Lng field will populate with a lat/lng object and a map will appear in the preview box, with a marker on the location.</li>
</ol>
<p>Access your data in the loop using the functions <strong>get_geocode_latlng()</strong> and <strong>get_geocode_address()</strong>, with the post ID passed as a parameter. Such as:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">Lat/Lng:
&lt;?php echo get_geocode_latlng($post-&gt;ID); ?&gt;
&nbsp;
Address:
&lt;?php echo get_geocode_address($post-&gt;ID); ?&gt;</pre></div></div>

<p>That&#8217;s it!</p>
<h3>Issues and Support</h3>
<p>If you need a hand or find a bug, please leave a comment here or <a class="external" href="https://github.com/halfempty/address-geocoder/issues">open a ticket on Github</a>. Thanks!</p>
]]></content:encoded>
			<wfw:commentRss>http://martyspellerberg.com/address-geocode-wordpress-plugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using the WordPress Featured Image / Post Thumbnail as a Google Maps Marker</title>
		<link>http://martyspellerberg.com/2012/03/using-the-wordpress-featured-image-post-thumbnail-as-a-google-maps-marker/</link>
		<comments>http://martyspellerberg.com/2012/03/using-the-wordpress-featured-image-post-thumbnail-as-a-google-maps-marker/#comments</comments>
		<pubDate>Mon, 19 Mar 2012 23:47:55 +0000</pubDate>
		<dc:creator>Marty Spellerberg</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Google Maps]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://martyspellerberg.com/?p=1670</guid>
		<description><![CDATA[This is a follow-up to my previous post on combining WordPress and Google Maps. Jayc asks: &#8220;Is there any way to change the MarkerImage to the featured image for the post?&#8221; Yes, there is! But one thing to keep in mind is that markers are not one image but two &#8212; the marker itself and [...]]]></description>
			<content:encoded><![CDATA[<p>This is a follow-up to my <a href="http://martyspellerberg.com/2012/02/tutorial-integrating-wordpress-and-google-maps-api-v-3/">previous post</a> on combining WordPress and Google Maps. Jayc asks:</p>
<blockquote>
<p><em>&#8220;Is there any way to change the MarkerImage to the featured image for the post?&#8221;</em></p>
</blockquote>
<p>Yes, there is! </p>
<p>But one thing to keep in mind is that markers are not one image but two &#8212; the marker itself and the shadow. What we&#8217;re going to cover here will show how to use the Featured Image as the marker, while continuing to use a single shadow across all posts. This means it is appropriate for markers that share the same size and silhouette.</p>
<p>We&#8217;ll be using the code from the <a href="http://martyspellerberg.com/2012/02/tutorial-integrating-wordpress-and-google-maps-api-v-3/">previous post</a> as the starting point.</p>
<h3>Initiate Featured Images</h3>
<p>Create a new file in your theme directory, called <em>functions.php</em>. In it, write:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Featured Images / Post Thumbnails</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'add_theme_support'</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    add_theme_support<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'post-thumbnails'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>This is the basic code. For more features see <a href="http://codex.wordpress.org/Post_Thumbnails" class="external">Post Thumbnails in the Codex</a>.</p>
<p>When you go to your Post Edit screen you will now see a metabox called Featured Image. Clicking the link, you will be prompted to upload a file. Once you have done that, click the &#8220;Use as featured image&#8221; link (it&#8217;s next to &#8220;Insert into post&#8221;).</p>
<h3>Make a marker declaration in the loop</h3>
<p>We&#8217;re going to move our marker declaration into the WordPress loop. We are going to add another parameter to our <strong>locations</strong> variable, so in <em>index.php</em> look for the line:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">info : document.getElementById('item<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$i</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>')</pre></div></div>

<p>And place a comma at the end of it.</p>
<p>Because Featured Images are not required by WordPress when publishing a post, we will test if one has been set and to provide a fallback. On the next line include the following test:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> has_post_thumbnail<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
	// There is a Featured Image
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
	// No Featured Image, use fallback
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>And under &#8220;use fallback&#8221;, define a fallback image</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">// No Featured Image, use fallback
marker : new google.maps.MarkerImage('<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> get_stylesheet_directory_uri<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>/pink_Marker.png', new google.maps.Size(20, 34) )</pre></div></div>

<h3>Get the path to the Featured Image</h3>
<p>The normal way to access the post thumbnail is to use the <strong>the_post_thumbnail()</strong> function, but this returns a full img tag. We want only the image path, so let&#8217;s make our own function that does this. Open <em>functions.php</em> and add:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> get_thumbnail_path<span style="color: #009900;">&#40;</span><span style="color: #000088;">$post_ID</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$post_image_id</span> <span style="color: #339933;">=</span> get_post_thumbnail_id<span style="color: #009900;">&#40;</span><span style="color: #000088;">$post_ID</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$post_image_id</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$thumbnail</span> <span style="color: #339933;">=</span> wp_get_attachment_image_src<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$post_image_id</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'post-thumbnail'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$thumbnail</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#40;</span>string<span style="color: #009900;">&#41;</span><span style="color: #000088;">$thumbnail</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$thumbnail</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$thumbnail</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>	
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>And back in <em>index.php</em>, under the &#8220;There is a Featured Image&#8221; comment, create a marker declaration that includes a call to the function:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">// There is a Featured Image
marker : new google.maps.MarkerImage('<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> get_thumbnail_path<span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>', new google.maps.Size(20, 34) )</pre></div></div>

<h3>Update the map JavaScript</h3>
<p>Last but not least, we&#8217;ll modify the <em>maps.js</em> to reflect our changes. Find the line that declares the &#8220;pinkmarker&#8221;:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> pinkmarker <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> google.<span style="color: #660066;">maps</span>.<span style="color: #660066;">MarkerImage</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'/wp-content/themes/mapdemo/pink_Marker.png'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">new</span> google.<span style="color: #660066;">maps</span>.<span style="color: #660066;">Size</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">20</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">34</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>and remove it; it&#8217;s no longer needed. Next, look for the line:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">icon<span style="color: #339933;">:</span> pinkmarker<span style="color: #339933;">,</span></pre></div></div>

<p>And change it to:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">icon<span style="color: #339933;">:</span> locations<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">marker</span><span style="color: #339933;">,</span></pre></div></div>

<p>And that&#8217;s it! Save everything and you should now see the featured image loaded as the marker.</p>
]]></content:encoded>
			<wfw:commentRss>http://martyspellerberg.com/2012/03/using-the-wordpress-featured-image-post-thumbnail-as-a-google-maps-marker/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Integrating WordPress and Google Maps API V.3</title>
		<link>http://martyspellerberg.com/2012/02/tutorial-integrating-wordpress-and-google-maps-api-v-3/</link>
		<comments>http://martyspellerberg.com/2012/02/tutorial-integrating-wordpress-and-google-maps-api-v-3/#comments</comments>
		<pubDate>Wed, 15 Feb 2012 14:00:51 +0000</pubDate>
		<dc:creator>Marty Spellerberg</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Google Maps]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://martyspellerberg.com/?p=1632</guid>
		<description><![CDATA[Here we will go through the steps for creating a Google Maps interface for a WordPress blog. Posts will appear as markers on the map, which you can click to reveal the post content in the Google Maps Infowindow. Download a ZIP of the complete example. I&#8217;m starting with a fresh WordPress install, which at [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://martyspellerberg.com/files/2012/02/mapsdemo0.jpg" alt="" style="width: 700px;" /></p>
<p>Here we will go through the steps for creating a Google Maps interface for a WordPress blog. Posts will appear as markers on the map, which you can click to reveal the post content in the Google Maps Infowindow.</p>
<p><a href="http://martyspellerberg.com/files/2012/02/mapdemo.zip">Download a ZIP of the complete example.</a></p>
<p>I&#8217;m starting with a fresh WordPress install, which at the time of this writing is v. 3.3.1. You may be modifying an existing theme, but for the sake of this tutorial, I&#8217;ll start a new one. But note that I&#8217;ll be doing only the minimum here to create a working demo, omitting much that is necessary for an actual, standards-compliant and useful website.</p>
<h3>Add Location Data to Posts</h3>
<p><img src="http://martyspellerberg.com/files/2012/02/mapsdemo1.jpg" alt="Custom Fields metabox" title="Custom Fields metabox" style="width: 289px; float: right; margin: 0 0 .5em 1.5em;" /></p>
<p>In order to know where to place a marker on a map, the Google Maps API needs to be supplied with latitude and longitude coordinates in the format of a <a href="http://code.google.com/apis/maps/documentation/javascript/reference.html#LatLng" class="external">LatLng object</a>. We&#8217;re going to include this as a Custom Field with our posts.</p>
<p>Navigate to the <strong>Post Edit</strong> page and scroll down to the <strong>Custom Fields</strong> box. (If you don&#8217;t see it, you may need to turn it on via the <strong>Screen Options</strong> button at the top of the page.)</p>
<p>Name the custom field &#8220;<strong>latlng</strong>.&#8221; Now, there are various geocoding services on the web that allow you convert an address to latlng (including the Google Maps API itself, but that&#8217;s another topic). For this example we&#8217;ll use the White House. Go to <a href="http://geocoder.us/" class="external">Geocoder.us</a> and enter &#8220;1600  Pennsylvania Avenue NW, Washington DC&#8221;. It will spit out a number in brackets such as <em>(38.898748, -77.037684)</em>. Use that as the value and press <strong>Add Custom Field</strong>.</p>
<p>If you like, you can optionally create a few more posts and geocode them with locations in Washington DC.</p>
<p class="alert"><strong>Update:</strong> I&#8217;ve published a plugin that simplifies the process of adding location data to posts; <a href="http://martyspellerberg.com/address-geocode-wordpress-plugin/">Use it instead!</a></p>
<h3>Initialize a Custom Theme</h3>
<p>In the <strong>wp-content/themes</strong> directory, create a new folder; mine will be called <strong>mapdemo</strong>. In this new folder, create a blank file called <em>style.css</em> and one called <em>index.php</em>; these are the minimum needed to created a WordPress theme. Also create a file called <em>map.js</em>.</p>
<p>To make our theme recognizable by WordPress we will place what&#8217;s called a <a href="http://codex.wordpress.org/Theme_Development#Theme_Stylesheet" class="external">theme header</a> into our <em>style.css</em>. The very minimum header is as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/* 
Theme Name: Map Demo
*/</span></pre></div></div>

<p>You can now go ahead and activate your theme using the WordPress dashboard (Appearance -> Themes). But if you load your blog at this point you will see that it&#8217;s totally blank. Let&#8217;s put in the bare-bones of an HTML page, with a couple of functions required by WordPress. Put the following into <em>index.php</em>:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&lt;html&gt;
	&lt;head&gt;
		&lt;title&gt;Maps Test&lt;/title&gt;
		<span style="color: #000000; font-weight: bold;">&lt;?php</span> wp_head<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
	&lt;/head&gt;
&nbsp;
	&lt;body&gt;
		<span style="color: #000000; font-weight: bold;">&lt;?php</span> wp_footer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
	&lt;/body&gt;
&lt;/html&gt;</pre></div></div>

<h3>Link the JavaScript Files</h3>
<p>Our map will be created using two JavaScript files: The Google Maps API library and our own <em>maps.js</em>. We do this in the <strong>head</strong> section of <em>index.php</em>, after the <strong>title</strong> tag. To include the API we will link directly to the file on Google&#8217;s server:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/javascript&quot;</span> src<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://maps.googleapis.com/maps/api/js?sensor=false&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>And to include maps.js we will do something similar, but you&#8217;ll notice that we use WordPress&#8217; <strong>get_stylesheet_directory_uri()</strong> function to dynamically write the path to the file in our theme directory:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&lt;script type=&quot;text/javascript&quot; src=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> get_stylesheet_directory_uri<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>/map.js&quot;&gt;&lt;/script&gt;</pre></div></div>

<h3>Create the Map</h3>
<p>WordPress uses something called <a href="http://codex.wordpress.org/The_Loop" class="external">The Loop</a> to display posts. Let&#8217;s get that started by testing if, given the parameters passed via the URL, WordPress has any posts to display. In <em>index.php</em>, after the opening <strong>body</strong> tag, write:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> have_posts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
	&lt;!-- WordPress has found matching posts --&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">else</span> <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
	&lt;!-- No matching posts, show an error --&gt;
	&lt;h1&gt;Error 404 &amp;mdash; Page not found.&lt;/h1&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Next create a DIV element that will be the container for our map; we&#8217;ll tell the API its name and Google will fill it with magic! We&#8217;ll use CSS to make it fill the window. After the line with the <strong>&#8220;WordPress has found matching posts&#8221;</strong> comment, write:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;map&quot;</span> style<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;width: 100%; height: 100%;&quot;</span><span style="color: #339933;">&gt;&lt;/</span>div<span style="color: #339933;">&gt;</span></pre></div></div>

<p>Now open up <em>maps.js</em>. We&#8217;re going to create a JavaScript function that loads in a map with a few settings, which I won&#8217;t go into the details of here, but are <a href="http://code.google.com/apis/maps/documentation/javascript/reference.html#MapOptions" class="external">well documented</a>. Write:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> initialize<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	map <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> google.<span style="color: #660066;">maps</span>.<span style="color: #660066;">Map</span><span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'map'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span> 
		zoom<span style="color: #339933;">:</span> <span style="color: #CC0000;">12</span><span style="color: #339933;">,</span> 
		center<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">new</span> google.<span style="color: #660066;">maps</span>.<span style="color: #660066;">LatLng</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">38.898748</span><span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">77.037684</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> 
		mapTypeId<span style="color: #339933;">:</span> google.<span style="color: #660066;">maps</span>.<span style="color: #660066;">MapTypeId</span>.<span style="color: #660066;">ROADMAP</span> 
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>But, like all functions, it&#8217;s not enough to define it &#8212; it must also be called. We&#8217;ll do this by modifying the <strong>body</strong> tag of <em>index.php</em>, like so:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>body onload<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;initialize()&quot;</span><span style="color: #339933;">&gt;</span></pre></div></div>

<p>Reload your page and you should now see a map filling the window, centred on Washington DC.</p>
<h3>Place the Markers</h3>
<p>The way we&#8217;re going to get our markers onto the map is to: </p>
<ol>
<li>create a list (an array) of locations;</li>
<li>specify the images we&#8217;re going to place at those locations;</li>
<li>then go through (iterate) through the list, placing each one.</li>
</ol>
<p>First up, the locations. We&#8217;re going to finish up that WordPress loop we started, where for each post we output an item in an array called &#8220;locations.&#8221; At this point we&#8217;re going to output only our &#8220;latlng&#8221; custom field, not the post title or content or any of the others. In <em>index.php</em>, right <strong>above the div with the ID of &#8220;map&#8221;</strong>, write this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&lt;script type=&quot;text/javascript&quot;&gt;
	var locations = [
		<span style="color: #000000; font-weight: bold;">&lt;?php</span>  <span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span> have_posts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> the_post<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
			<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> get_post_meta<span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'latlng'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!==</span> <span style="color: #0000ff;">''</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
				{
					latlng : new google.maps.LatLng<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> get_post_meta<span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'latlng'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>, 
				},
			<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
		<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++;</span> <span style="color: #b1b100;">endwhile</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
	];
&lt;/script&gt;</pre></div></div>

<p>Next we&#8217;ll define the images we want to use as markers. Each marker has two parts &#8212; the marker itself and its shadow, and for each you will supply paths to images of your choosing; I&#8217;ve included a couple in the ZIP, linked above, or you can use your own. Upload the images into your theme folder. At the very top of <em>maps.js</em>, <strong>above the initialize function</strong>, write:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> pinkmarker <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> google.<span style="color: #660066;">maps</span>.<span style="color: #660066;">MarkerImage</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'/wp-content/themes/mapdemo/pink_Marker.png'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">new</span> google.<span style="color: #660066;">maps</span>.<span style="color: #660066;">Size</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">20</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">34</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> shadow <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> google.<span style="color: #660066;">maps</span>.<span style="color: #660066;">MarkerImage</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'/wp-content/themes/mapdemo/shadow.png'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">new</span> google.<span style="color: #660066;">maps</span>.<span style="color: #660066;">Size</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">37</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">34</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>If you are using your own images you will want to check Google&#8217;s documentation of the <a href="http://code.google.com/apis/maps/documentation/javascript/reference.html#MarkerImage" class="external">MarkerImage options</a> to see what each part of these lines mean, so that you can customize them. </p>
<p class="alert"><strong>Note:</strong> I&#8217;ve created a follow-up post on <a href="">using the post&#8217;s Featured Image as the marker</a>.</p>
<p>And the final step is to loop through the locations, placing a marker for each onto the map. In <em>maps.js</em>, <strong>within the &#8220;initialize&#8221; function, after the &#8220;var map&#8230;&#8221; block</strong>, write:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> locations.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>  
	<span style="color: #003366; font-weight: bold;">var</span> marker <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> google.<span style="color: #660066;">maps</span>.<span style="color: #660066;">Marker</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    	position<span style="color: #339933;">:</span> locations<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">latlng</span><span style="color: #339933;">,</span>
		icon<span style="color: #339933;">:</span> pinkmarker<span style="color: #339933;">,</span>
		shadow<span style="color: #339933;">:</span> shadow<span style="color: #339933;">,</span>
		map<span style="color: #339933;">:</span> map
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Reload your page and you should now see your marker(s) placed on the map.</p>
<h3>Enable the Infowindow</h3>
<p>Our last task is to create a Google Maps &#8220;infowindow&#8221; which will pop-up when a marker is clicked, showing the title and content of the post. We will do this by:</p>
<ol>
<li>outputting the content into a hidden div;</li>
<li>referencing that div in our array of locations;</li>
<li>and adding what&#8217;s known as a &#8220;click listener&#8221; to our JavaScript function to open the window.</li>
</ol>
<p>First up, the content. This will be a a second &#8220;while&#8221; loop, immediately before the one we wrote previously. It will output a series of DIVs, each with a unique ID and containing content to be shown in the infowindow. In <strong>index.php</strong>, directly following the <strong>&#8220;matching posts&#8221;</strong> comment line, write:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&lt;div style=&quot;display: none;&quot;&gt;
	<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span> have_posts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> the_post<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
		<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> get_post_meta<span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'latlng'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!==</span> <span style="color: #0000ff;">''</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
			&lt;div id=&quot;item<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$i</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;
				&lt;p&gt;&lt;a href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_permalink<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/a&gt;&lt;/p&gt;
				<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_content<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
			&lt;/div&gt;
		<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
		<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++;</span>	<span style="color: #000000; font-weight: bold;">?&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endwhile</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;/div&gt;</pre></div></div>

<p>Next add a reference to these DIVs to our locations object. Directly after this line:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">latlng <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">new</span> google.<span style="color: #660066;">maps</span>.<span style="color: #660066;">LatLng</span><span style="color: #339933;">&lt;?</span>php echo get_post_meta<span style="color: #009900;">&#40;</span>$post<span style="color: #339933;">-&gt;</span>ID<span style="color: #339933;">,</span> <span style="color: #3366CC;">'latlng'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #339933;">?&gt;,</span></pre></div></div>

<p>Add this:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">info <span style="color: #339933;">:</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'item&lt;?php echo $i; ?&gt;'</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>Now define the infowindow (<a href="http://code.google.com/apis/maps/documentation/javascript/reference.html#InfoWindow" class="external">documentation at Google</a>). Switch over to <em>maps.js</em> and, at the very top, write this:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> infowindow <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> google.<span style="color: #660066;">maps</span>.<span style="color: #660066;">InfoWindow</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Finally, add a click listener for each marker. Within the &#8220;for&#8230;&#8221; block of the &#8220;initialize&#8221; function, after the &#8220;var marker&#8230;&#8221; block</strong>, write:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">google.<span style="color: #660066;">maps</span>.<span style="color: #660066;">event</span>.<span style="color: #660066;">addListener</span><span style="color: #009900;">&#40;</span>marker<span style="color: #339933;">,</span> <span style="color: #3366CC;">'click'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>marker<span style="color: #339933;">,</span> i<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    infowindow.<span style="color: #660066;">setContent</span><span style="color: #009900;">&#40;</span>locations<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">info</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    infowindow.<span style="color: #000066;">open</span><span style="color: #009900;">&#40;</span>map<span style="color: #339933;">,</span> marker<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>marker<span style="color: #339933;">,</span> i<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>And that&#8217;s it! Reload the page and you will now be able to click the marker(s), opening up an infowindow containing the post content. Mission accomplished!</p>
]]></content:encoded>
			<wfw:commentRss>http://martyspellerberg.com/2012/02/tutorial-integrating-wordpress-and-google-maps-api-v-3/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Santa Cruz Museum of Art and History</title>
		<link>http://martyspellerberg.com/santa-cruz-museum-of-art-and-history/</link>
		<comments>http://martyspellerberg.com/santa-cruz-museum-of-art-and-history/#comments</comments>
		<pubDate>Wed, 16 Nov 2011 18:12:34 +0000</pubDate>
		<dc:creator>Marty Spellerberg</dc:creator>
				<category><![CDATA[Work]]></category>
		<category><![CDATA[Websites]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://martyspellerberg.com/?p=1460</guid>
		<description><![CDATA[Website, 2011&#8211;Present www.santacruzmah.org LANGUAGES JavaScript, PHP, HTML, CSS CMS WordPress Executive Director Nina Simon (of the blog Museum 2.0) is leading The Museum of Art and History in its mission to establish itself as the cultural center of Santa Cruz. The museum’s innovative vision is founded on responsive engagement with its local communities; my role [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://martyspellerberg.com/files/2011/11/mah.png" alt="Santa Cruz Museum of Art and History" class="expand" /></p>
<div class="infobox">
<p>Website, 2011&ndash;Present<br />
<a href="www.santacruzmah.org" class="external">www.santacruzmah.org</a> </p>
<p><strong>LANGUAGES</strong><br />
JavaScript, PHP, HTML, CSS </p>
<p><strong>CMS</strong><br />
WordPress</p>
</div>
<p>Executive Director Nina Simon (of the blog Museum 2.0) is leading The Museum of Art and History in its mission to establish itself as the cultural center of Santa Cruz. The museum’s innovative vision is founded on responsive engagement with its local communities; my role was to manifest this as a website, empowering staff with an intuitive, easy to use configuration.</p>
]]></content:encoded>
			<wfw:commentRss>http://martyspellerberg.com/santa-cruz-museum-of-art-and-history/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Convenience</title>
		<link>http://martyspellerberg.com/convenience/</link>
		<comments>http://martyspellerberg.com/convenience/#comments</comments>
		<pubDate>Wed, 16 Nov 2011 18:08:55 +0000</pubDate>
		<dc:creator>Marty Spellerberg</dc:creator>
				<category><![CDATA[Work]]></category>
		<category><![CDATA[Websites]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://martyspellerberg.com/?p=1456</guid>
		<description><![CDATA[Website, 2011&#8211;Present www.conveniencegallery.com LANGUAGES JavaScript, PHP, HTML, CSS CMS WordPress Convenience is a contemporary art window gallery in Toronto. Having outgrown its earlier design, this new site presents the complete archive of exhibitions in an accordion format that includes the ability to bookmark/link to a specific open-state.]]></description>
			<content:encoded><![CDATA[<p><img src="http://martyspellerberg.com/files/2011/11/convenience.png" alt="convenience" class="expand" /></p>
<div class="infobox">
<p>Website, 2011&ndash;Present<br />
<a href="http://www.conveniencegallery.com" class="external">www.conveniencegallery.com</a></p>
<p><strong>LANGUAGES</strong><br />
JavaScript, PHP, HTML, CSS </p>
<p><strong>CMS</strong><br />
WordPress</p>
</div>
<p>Convenience is a contemporary art window gallery in Toronto. Having outgrown its earlier design, this new site presents the complete archive of exhibitions in an accordion format that includes the ability to bookmark/link to a specific open-state.</p>
]]></content:encoded>
			<wfw:commentRss>http://martyspellerberg.com/convenience/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

