<?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; JavaScript</title>
	<atom:link href="http://martyspellerberg.com/tag/javascript/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.1</generator>
		<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>Creating a WordPress Tag Search using jQuery</title>
		<link>http://martyspellerberg.com/2011/11/creating-a-wordpress-tag-search-using-jquery/</link>
		<comments>http://martyspellerberg.com/2011/11/creating-a-wordpress-tag-search-using-jquery/#comments</comments>
		<pubDate>Tue, 08 Nov 2011 14:00:55 +0000</pubDate>
		<dc:creator>Marty Spellerberg</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://martyspellerberg.com/?p=1439</guid>
		<description><![CDATA[The WordPress taxonomy functions make it easy to give your for your visitors links to per-tag archives of posts. But is it possible to give them archives of more than one tag? Sure it is! The technique applied on Seth Anderson&#8217;s photo site. You can preview the code here. &#8220;Any&#8221; &#38; &#8220;And&#8221; Tag Intersections By [...]]]></description>
			<content:encoded><![CDATA[<p>The WordPress taxonomy functions make it easy to give your for your visitors links to per-tag archives of posts. But is it possible to give them archives of more than one tag? Sure it is! </p>
<p><img src="http://martyspellerberg.com/files/2011/11/tagsearch.jpg" alt="" title="tagsearch" /></p>
<p class="caption">The technique applied on <a href="http://b12partners.net/photo/" class="external">Seth Anderson&#8217;s photo site</a>.</p>
<p>You can <a href="/files/2011/11/tagsearch.html">preview the code here</a>.</p>
<h3>&#8220;Any&#8221; &amp; &#8220;And&#8221; Tag Intersections</h3>
<p>By passing parameters via the URL, WordPress will create pages for the intersections of multiple tags. This means we can get posts with <strong>any</strong> of the tags by separating terms with a <strong>comma</strong>, like so: <strong>/?tag=onetag,anothertag</strong>. That is to say a post must have one but need not have all of the tags to qualify.</p>
<p>Conversely, we can get posts with <strong>all</strong> of the tags by separating terms with a <strong>plus</strong>, like so: <strong>/?tag=onetag+anothertag</strong>. This will return only posts that have every tag. There&#8217;s various issues with the default output of this, however, so go ahead and install the <a href="http://wordpress.org/extend/plugins/tdo-tag-fixes/" class="external">tTDO Tag Fixes plugin</a>. Running this plugin changes the &#8220;all&#8221; URL string to <strong>/?tdo_tag=onetag+anothertag</strong>.</p>
<h3>Show All Tags</h3>
<p>The first thing we&#8217;ll do is print out all the tags, with links, onto the page. This goes in your theme&#8217;s <strong>functions.php</strong>:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> showalltags<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000088;">$my_query</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> WP_Query<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'posts_per_page=1'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$my_query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">have_posts</span><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: #000088;">$my_query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">the_post</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$tags</span> <span style="color: #339933;">=</span> get_tags<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$html</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$tags</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$tag</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$tag_link</span> <span style="color: #339933;">=</span> get_tag_link<span style="color: #009900;">&#40;</span><span style="color: #000088;">$tag</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">term_id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$html</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;a href='<span style="color: #006699; font-weight: bold;">{$tag_link}</span>' title='<span style="color: #006699; font-weight: bold;">{$tag-&gt;name}</span> Tag' class='<span style="color: #006699; font-weight: bold;">{$tag-&gt;slug}</span>'&gt;&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$html</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">{$tag-&gt;name}</span>&lt;/a&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$html</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">endwhile</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>And output it somewhere in your theme like so:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;div class=&quot;taxonomies&quot;&gt;
	&lt;h3 id=&quot;tags&quot;&gt;Tags&lt;/h3&gt;
	&lt;div class=&quot;taglist&quot;&gt;&lt;?php showalltags(); ?&gt;&lt;/div&gt;
&lt;/div&gt;</pre></td></tr></table></div>

<h3>Rewrite the markup</h3>
<p>Now we&#8217;re going to use JavaScript to update the page&#8217;s markup to reflect the JavaScript-dependent functionality we&#8217;re building. We do this with JS because these controls are only relevant to users with JS-enabled browsers &#8212; for others their presence would only be confusing. </p>
<p>Get your <strong>jQuery(document).ready(function($)</strong> started then include this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> initialLoad <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.taxonomies h3'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Select one or more tags, then press &lt;em&gt;&amp;ldquo;Search Tags&amp;rdquo;&lt;/em&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.taglist'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">before</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;div class=&quot;searchcontrols&quot;&gt;&lt;span&gt;Find photos with &lt;/span&gt;&lt;a id=&quot;any&quot; class=&quot;tagtoggle selected&quot;&gt;any&lt;/a&gt;&lt;span class=&quot;slash&quot;&gt; / &lt;/span&gt;&lt;a id=&quot;all&quot; class=&quot;tagtoggle&quot;&gt;all&lt;/a&gt;&lt;span&gt; of the selected criteria&lt;/span&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.taxonomies'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;a class=&quot;searchtags&quot;&gt;Search Tags&lt;/a&gt;&lt;/div&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
<span style="color: #009900;">&#125;</span>
&nbsp;
initialLoad<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h3>Capture tag clicks</h3>
<p>When a user clicks a tag, we&#8217;ll override the link and instead add the class &#8220;selectedtag&#8221;:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.taglist a'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'click'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	event.<span style="color: #660066;">preventDefault</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hasClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'selectedtag'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'selectedtag'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'selectedtag'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h3>Toggle &#8220;Any&#8221; &amp; &#8220;And&#8221;</h3>
<p>Similarly, capture clicks to the controls:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.tagtoggle'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'click'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	event.<span style="color: #660066;">preventDefault</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.tagtoggle'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'selected'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'selected'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h3>Construct the URL</h3>
<p>This function is the core of the mechanism:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> searchTags<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> optionTexts <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">// For each selected tag...</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.selectedtag'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</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> 
&nbsp;
		<span style="color: #006600; font-style: italic;">// capture the slug from class (stripping out the &quot; selectedtag&quot;)</span>
		<span style="color: #003366; font-weight: bold;">var</span> str <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'class'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/\sselectedtag+/g</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #006600; font-style: italic;">// and add it to an array</span>
		optionTexts.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span>str<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
&nbsp;
	<span style="color: #006600; font-style: italic;">// Set the URL format appropriate to the selected search type</span>
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#any'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hasClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'selected'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #003366; font-weight: bold;">var</span> param <span style="color: #339933;">=</span> <span style="color: #3366CC;">'tag'</span><span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> separator <span style="color: #339933;">=</span> <span style="color: #3366CC;">','</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #003366; font-weight: bold;">var</span> param <span style="color: #339933;">=</span> <span style="color: #3366CC;">'tdo_tag'</span><span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> separator <span style="color: #339933;">=</span> <span style="color: #3366CC;">'+'</span><span style="color: #339933;">;</span>			
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">// Put the tag list together</span>
	<span style="color: #003366; font-weight: bold;">var</span> tagstring <span style="color: #339933;">=</span> optionTexts.<span style="color: #660066;">join</span><span style="color: #009900;">&#40;</span>separator<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">// And send them off to the final, constructed URL</span>
	window.<span style="color: #660066;">location</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'/?'</span> <span style="color: #339933;">+</span> param <span style="color: #339933;">+</span> <span style="color: #3366CC;">'='</span> <span style="color: #339933;">+</span> tagstring<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h3>Enable the Search Button</h3>
<p>Last but not least, the action on the search button calls the search function:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.searchtags'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'click'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	event.<span style="color: #660066;">preventDefault</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	searchTags<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>And that&#8217;s it! You can take a look at <a href="/files/2011/11/tagsearch.js">the full JavaScript in context here</a>.</p>
<p><em><strong>Updated 12/10/11</strong> to capture the tag slug from the class, rather than inferring it from the tag name.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://martyspellerberg.com/2011/11/creating-a-wordpress-tag-search-using-jquery/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Interactive Touchscreen Interface using jQuery and HTML5 Video</title>
		<link>http://martyspellerberg.com/2011/10/interactive-touchscreen-interface-using-jquery-and-html5-video/</link>
		<comments>http://martyspellerberg.com/2011/10/interactive-touchscreen-interface-using-jquery-and-html5-video/#comments</comments>
		<pubDate>Thu, 27 Oct 2011 14:00:39 +0000</pubDate>
		<dc:creator>Marty Spellerberg</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Video]]></category>

		<guid isPermaLink="false">http://martyspellerberg.com/?p=1392</guid>
		<description><![CDATA[An interface to display short video clips in a gallery setting. In 2009 artist Midi Onodera created a series of 52 short clips designed for podcasting. I have been fortunate to be involved in this project, providing technical support and new media development. When exhibition opportunities arise, such as Onodera&#8217;s recent show at Concordia University [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://martyspellerberg.com/files/2011/10/midi-interface1-1024x678.jpg" alt="An interface to display short video clips in a gallery setting." /></p>
<p class="caption">An interface to display short video clips in a gallery setting.</p>
<p>In 2009 artist Midi Onodera created a series of <a href="http://midionodera.com/category/series/movie-of-the-week/" class="external">52 short clips</a> designed for podcasting. I have been fortunate to be involved in this project, providing technical support and new media development. When exhibition opportunities arise, such as <a href="http://midionodera.com/2011/vidoodles-intimate-cinema-at-concordia-university/" class="external">Onodera&#8217;s recent show at Concordia University</a> in Montreal, we grapple with ways to present these new-media-specific works in the gallery setting. Knowing Concordia had some sweet gear, Onodera chose show this series on a large touch-screen monitor. I designed and implemented the interface using web-standard technologies including jQuery and HTML5 Video.</p>
<p>I have posted <a href="https://github.com/halfempty/Onodera-Video-Interface" class="external">the code on Github</a>. It uses a version of the <a href="http://martyspellerberg.com/2011/10/jquery-vertical-center/">jQuery vertical center function</a> I previously posted, as well as some other interface effects. One of my favourite of its features is the randomization: The thumbnails are shuffled as the page is loaded and then each moves to the end of the page upon being selected. At its core are the functions to load and play the clips.</p>
<h3>Swapping Sources in an HTML 5 Video</h3>
<p>The interface provides access to 53 video clips, but rather than giving each its own instance, I set up an single video element, omitting a source.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;video class=&quot;video&quot; id=&quot;video&quot; controls=&quot;&quot; autoplay=&quot;&quot; width=&quot;640&quot; height=&quot;426&quot;&gt;&lt;/video&gt;</pre></td></tr></table></div>

<p>And then, when a video is selected, its source is added in and the element begins to play.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">$('.video').attr('src','movies/' + movieNum + '.m4v');
document.getElementById('video').play();</pre></td></tr></table></div>

<p>But the strangest thing happened when the next video is loaded and played: The audio from the first clip would play along with the new! I tried all sorts of things, including completely unloading the video element and creating a new one for each cycle, but still the audio could be heard. What a strange bug!</p>
<p>In the end I found it could be solved by, upon closing the clip, pausing the playback and then removing the video source:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">document.getElementById('video').pause();
$('.video').removeAttr('src');</pre></td></tr></table></div>

<p>All of this can be seen in-context over at <a href="https://github.com/halfempty/Onodera-Video-Interface" class="external">Github</a>.</p>
<div style="overflow: hidden;">
<div style="width: 340px; float: left"><img src="http://martyspellerberg.com/files/2011/10/midi-interface3-1024x1024.jpg" alt="Playing a video." style="width: 338px; height: 338px" /></p>
<p class="caption">Playing a video.</p>
</div>
<div style="width: 340px; float: right"><img src="http://martyspellerberg.com/files/2011/10/midi-interface2-1024x1024.jpg" alt="The touch-screen rig." style="width: 338px; height: 338px" /></a></p>
<p class="caption">The touch-screen rig.</p>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://martyspellerberg.com/2011/10/interactive-touchscreen-interface-using-jquery-and-html5-video/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery Vertical Center</title>
		<link>http://martyspellerberg.com/2011/10/jquery-vertical-center/</link>
		<comments>http://martyspellerberg.com/2011/10/jquery-vertical-center/#comments</comments>
		<pubDate>Fri, 21 Oct 2011 04:44:28 +0000</pubDate>
		<dc:creator>Marty Spellerberg</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://martyspellerberg.com/?p=1381</guid>
		<description><![CDATA[This is to center elements vertically in the middle of the browser window. It&#8217;s pretty straightforward, but note line 4. On one of the sites I used this on the centered element needed to appear in the middle of the field under a top navigation bar, so this looks for that element and factors that [...]]]></description>
			<content:encoded><![CDATA[<p>This is to center elements vertically in the middle of the browser window.</p>
<p>It&#8217;s pretty straightforward, but <strong>note line 4</strong>. On one of the sites I used this on the centered element needed to appear in the middle of the field under a top navigation bar, so this looks for that element and factors that into the calculation.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">jQuery.fn.center = function () {
&nbsp;
	var $t = ( ( $(window).height() - this.outerHeight() ) / 2);
	var $h = $('.header').outerHeight();
&nbsp;
      	if ( ( $(window).height() - $h ) &gt;= this.outerHeight() ) {
		jQuery('.shade').fillWindow();
&nbsp;
    		this.css({ &quot;position&quot;:&quot;fixed&quot;,&quot;top&quot; : ($t + &quot;px&quot;) });
&nbsp;
		if ( $(window).width() &gt;= this.outerWidth() ) {
    			this.css(&quot;left&quot;, (($(window).width() - this.outerWidth()) / 2) + $(window).scrollLeft() + &quot;px&quot;);
		}
&nbsp;
	} else {
		// Don't do
	}
&nbsp;
	this.show();
&nbsp;
   	return this;
&nbsp;
}</pre></td></tr></table></div>

<p>And then use it like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">$('.someElement').center();</pre></td></tr></table></div>

<p>Also, do remember to use this only once all the elements have loaded. It&#8217;ll come out wrong if you center before, for instance, all the images have come in. So make sure the element is at its full dimensions before you fire this.</p>
]]></content:encoded>
			<wfw:commentRss>http://martyspellerberg.com/2011/10/jquery-vertical-center/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

