WordPress
Page 3 of 5
Center a Google Map on the Latest WordPress Post
This is a follow-up to my previous post on integrating WordPress and Google Maps. Damien asks:
“Would it be possible to centre the map on my latest post?”
Yes, it is!
This builds off the example in the previous post and I’m using the Address Geocoder plugin to set latlngs. You can see and download the entire working example at GitHub.
Output the JavaScript with PHP
The line that defines the center of the map is presently specified in a static way — we arbitrarily chose a location and included its latlng in the JavaScript function initialize(). Now we will revise this so that it is pulling a dynamic variable from WordPress. There are a number of ways to accomplish this, but here we’re going to go with the most straightforward, which is to move the entire contents of the static maps.js into the dynamic index.php.
Open maps.js and copy the contents to your clipboard. Then open index.php and look for this line:
<script type="text/javascript" src="<?php echo get_stylesheet_directory_uri() ?>/map.js"></script> |
Remove the src parameter and paste the JavaScript between the opening and closing tags so that you have this:
<script type="text/javascript"> var infowindow = new google.maps.InfoWindow(); var pinkmarker = new google.maps.MarkerImage('/wp-content/themes/mapdemo/pink_Marker.png', new google.maps.Size(20, 34) ); var shadow = new google.maps.MarkerImage('/wp-content/themes/mapdemo/shadow.png', new google.maps.Size(37, 34) ); function initialize() { map = new google.maps.Map(document.getElementById('map'), { zoom: 12, center: new google.maps.LatLng(38.898748, -77.037684), mapTypeId: google.maps.MapTypeId.ROADMAP }); for (var i = 0; i < locations.length; i++) { var marker = new google.maps.Marker({ position: locations[i].latlng, icon: pinkmarker, shadow: shadow, map: map }); google.maps.event.addListener(marker, 'click', (function(marker, i) { return function() { infowindow.setContent(locations[i].info); infowindow.open(map, marker); } })(marker, i)); } } </script> |
Next we are going to add in a simple WordPress loop to get the single latest post and assign its latlng to a PHP variable.
Right inside the initialize() function, before the definition of map, add:
<?php $the_query = new WP_Query('showposts=1'); while ( $the_query->have_posts() ) : $the_query->the_post(); $coordinates = get_geocode_latlng($post->ID); endwhile; ?> |
And lastly, output that variable to the line that defines the map’s center, in place the static latlng. Look for this line:
center: new google.maps.LatLng(38.898748, -77.037684), |
And change it to this:
center: new google.maps.LatLng<?php echo $coordinates ?>, |
Done! On load, your map will now center on the marker of the latest post.
Website for Photographer Andres Gonzalez

Andres Gonzalez’s website
I recently had the pleasure of creating sites with documentary photographer Andres Gonzalez. EachAndreshas an amazing eye and strong sense of narrative, which he brought to his layout and navigation. The site is built on WordPress, with custom a gallery-presentation plugin and theme.
Website for Photographer Carolyn Drake

I recently had the pleasure of creating sites with documentary photographer Carolyn Drake. Carolyn has an amazing eye and strong sense of narrative, which she brought to her layout and navigation. This site is built on WordPress, with custom gallery-presentation plugins and theme.
Website redesign for the Santa Cruz Museum of Art & History
Like many of my museum colleagues, I’m a big fan of Nina Simon’s blog, Museum 2.0. When the Santa Cruz Museum of Art & History, of which she is the director, needed a new website, I jumped at the opportunity. Simon praised my work, saying,
“Marty is everything I could have wanted from a designer — he overdelivered on my vague directives and pushed me to think more rigorously about what we were trying to do.”
The project was a full website redesign and redevelopment. We migrated from a legacy CMS to WordPress, added new content and functionality, and redesigned to match the MAH’s new visual identity.

Template Part Shortcode and Carolyn Google Analytics WordPress Plugins
I’ve released a couple more plugins to the WordPress plugin directory. They are the result of day-to-day maintenance on a variety of WordPress sites.
Template Part Shortcode
Template parts are reusable snippets of code stored in your theme directory. Normally, they are called by other template files using the get_template_part() function. This plugin creates a shortcode for calling template parts from the body of a post.
Shortcode usage is: [template part=”somepart”].
Template parts must be stored in a “parts” folder within your theme directory.
Get the plugin from the WordPress plugin directory.
Follow on GitHub.
Carolyn Google Analytics
This is a plugin for embedding a Google Analytics (GA) tracking code in your site. It has two features:
- It stores the GA code as a site setting. This means no modifying theme files, which is especially useful in a Multisite context;
- The GA code is NOT inserted for logged-in users, meaning you won’t run up your visitor counts as you administer your site;
And that’s it! It works with Google’s “Asynchronous” tracking code, which goes in the page’s head.
Get the plugin from the WordPress plugin directory.
Follow on GitHub.
Website for Photographer Samuel James

I’m happy to launch a new website for documentary photographer Samuel A. James, an American working in Nigeria. The site runs the WordPress theme/plugin package I’ve dubbed “Carolyn”, after its initial commissioner, Carolyn Drake. The idea behind this package is to create a system that can be used to quickly deploy portfolio sites of a certain kind. To adapt the package to James’ needs I added features like an automatically-advancing slideshow and, most importantly, the ability to give each site a unique layout / style sheet. Check it out!
WordPress 3.5 media_order Issue Affects Custom Galleries
The revamped Add Media interface in WordPress 3.5 improves a great many things about media management. It’s fantastic and thanks go out to the team for all the hard work!
Unfortunately, the removal of a visible menu order field and the associated “Sort by Ascending / Descending” links has created an issue that affects some plugins and themes.
For instance, I often code templates that detect all images attached to a post and display them in a slideshow. In these cases I rely on the menu_order field to set the image order. Here’s a line I use often:

I’ll walk through the steps that illuminate the issue. First we’ll create a new post and upload a bunch of images to it. Using the “Uploaded to this post” filter, they appear to be in the correct order…

When we look in the DB, we see that their menu orders are actually all “0”. As we will see, this has some funny effects.

We close the Media Upload window and continue our work. When we return to the Media Upload screen, the image order appears to have been reversed.

Now, at this point there’s been no actual change in the DB. But it’s not unreasonable for the user to be a bit confused, and to manually make a change to the order. Here I’ve dragged the 01 image to the first spot:

When I do this, WordPress finally assigns a non-zero order to all of these images. Unfortunately, the order being assigned is the same (backwards) order that we are seeing via the interface.

As you can see, “image02” has been assigned a menu order of 25. To properly reorder the images involves manually dragging and dropping, which can be quite onerous with large image sets.
Origins: A User-Generated Museum Exhibit created using iPads, Google Maps and WordPress

Origins: The Birth and Rise of Chinese American Communities in Los Angeles is a permanent, cutting edge exhibition celebrating the growth and development, since the 1890s, of Chinese American enclaves from Downtown Los Angeles to the San Gabriel Valley.
Origins was designed for the Chinese American Museum, Los Angeles by THINK Jacobson & Roth. I was fortunate to be brought on as a member of the THINK team, providing start-to-finish design and development on the exhibit’s media component, Origins online. An interactive website available in the exhibit’s Monterey Park area, Origins online allows visitors to find and share great places, stories and resources of the San Gabriel Valley and other LA neighborhoods. The in-gallery presentation includes a table with two iPads for accessing the website, and a third for recording video of visitors’ own stories.
Agile Design Process, No Wireframes.

One of the earliest decisions we made on the project was to forego traditional wireframes.
The project team, consisting of CAM’s Steve Wong and Michael Truong, and THINK’s Lori Jacobson and Carla Roth, had a strong broad-strokes image of what they wanted. At our first meeting they described a map of the San Gabriel Valley, with markers indicating points of interest submitted by the public. And so, to our second meeting, I brought a working prototype demonstrating that functionality.
We continued in that vein for much of the project. At each meeting we reviewed the current state of the application and came to a consensus on development priorities for the next week. Feeling our way forward, we’d field lots of ideas and implement those with the highest priority. This process reminds me of the saying, “crossing the river by stepping on stones.”
Rather than discussing abstractions and hypotheticals, this approach allowed us to base our decisions on real experiences with a working interface. And rather than spending our limited time producing paper documents such as wireframes and mockups, all our effort went toward expressing ideas in code that could be poked, prodded, tested and, ultimately, launched.
“When Marty proposed working without wireframes, I immediately responded positively to this idea. With a tight budget and a hands-on client, working with iterative prototypes was the way to go. Rather than lingering in pre-production, this allowed us to quickly make team decisions and try things out in a very real way.”
— Carla Roth
At about the two-thirds mark we took a step back and presented our work, and the decisions it embodied, to Executive Director Michael Duchemin, who gave it his blessing. As the physical exhibition took shape we took a break, and by the time we reconvened the launch date had begun to loom large. So we locked development on new functionality and turned our focus to fit and finish.
I proposed that, since the site would be presented in-gallery using iPads, we adopt the iOS design vernacular. Applying gradients, highlights, textures and pop-overs would involve adding substantial complexity to the code, however, and increase the cost-of-change. For this reason we decided it was finally appropriate to create a mock-up and secure a more traditional client sign-off. From there we turned to browser testing and bug barbecue, then finished with the physical installation and documentation.

Google Maps + WordPress + iPads
Curator Steve Wong described his own extensive use of Google Maps in charting the region’s activity and history, and imagined enabling something similar for the community. I had previous experience with the Google Maps Javascript API so was able to hit the ground running. We chose WordPress for the CMS because of its ease-of-use for both development and content management. Additionally, I knew that the Gravity Forms plugin would allow us to fulfill the user-submission aspect of the project. And we chose Media Temple to host based on the suitability of their offering and my own familiarity with their setup. (Their location in Los Angeles was a bonus!)
The implementation’s core technical concept is described in my WordPress + Google Maps tutorial. Also, this project was the original motivator for the Address Geocoder WordPress plugin, which is now available from the WordPress plugin directory. The other aspect of the technical challenge was creating a JavaScript-heavy site that would look its best on 3rd generation iPads running the Kiosk Pro browser, while also performing on the desktop.
I’m happy to answer questions regarding the technical aspects of this project, including the Google Maps API, WordPress or, more generally, our agile approach and deploying web-based museum exhibits using iPads. Questions about the overall exhibit should be directed to THINK Jacobson & Roth.
The Chinese American Museum is a great space with a ton of history and a staff truly committed to serving their community and preserving its heritage. If you’re in LA, go see the exhibit!
Website for Photographer Adam Nadel

Adam Nadel’s photographic practice is located “at the intersections of journalism, science, and human rights.” He knew exactly what he wanted and was a joy to work with! Using the WordPress-based package I’ve been developing, we were able put his site together quickly and efficiently.
California Missions microsite for The Huntington Library

I’m happy to report the launch of Exploring the California Missions, a website I designed and developed for The Huntington Library, Art Collections, and Botanical Gardens.
Using the lens of California Mission history, Exploring the California Missions presents a suite of lessons intended to help teachers and fourth grade students develop the critical skills needed to work with primary sources. The website was produced in conjunction with the exhibit Junípero Serra and the Legacies of the California Missions.
Located in San Marino, California, The Huntington is a collections-based research and educational institution serving scholars and the general public.
The website is built on WordPress, with the classroom presentations presented using SlideShare. This project was created in association with Think ROTH Projects and in collaboration with a cross-departmental team from The Huntington.
Membership microsite for the Santa Cruz Museum of Art & History

I’ve been working with the Santa Cruz Museum of Art & History to develop a series of low-tech, low-cost strategies and systems to track, celebrate, and act on personal interactions with visitors.
“Like many small museums, the MAH cannot afford expensive ticketing or membership software systems,” says Executive Director Nina Simon. “We have very high ability to form relationships with visitors, but low ability to capitalize on those interactions.”
One of the initiatives we’ve undertaken to address this discrepancy was the creation a new online membership storefront that integrates with the Museum’s website, other membership materials, and philosophy. I designed and developed the site in close collaboration with Museum staff, beginning with a visit to the MAH.
“We were fortunate to have Marty in our office as we outlined how the site would look and function, and he literally cut and collaged together our existing printed membership materials to build an online system that looked and felt the same as our existing paper system. He’s created a less daunting transition for our members, who are accustomed to those materials.”
— Karen Bush, Membership Director
Located in downtown Santa Cruz, California, The Santa Cruz Museum of Art & History is a community-centered origination whose vision is to become a thriving, central gathering place where local residents and visitors have the opportunity to experience art, history, ideas, and culture.
The website is built on WordPress, using the Gravity Forms plugin.
WordPress migration for the Chinese American Museum, Los Angeles

The Chinese American Museum, Los Angeles wanted a Content Management System, so that non-technical staff could make changes on their own. And, based on the experience using it for the Origins site, they wanted WordPress. So that’s exactly what we did!
Overall, this work was about making life easier for CAM staff. We left the visual design and layout largely the same as it was — this was not a full-scale website redesign — but did refactor aspects of the HTML and CSS to simplify content management, such as taking styles and classes out of the content where possible.
The one area we did redesign, however, was the home page. The previous layout was designed to be “above the fold,” which constrained the amount of information it could present. Our redesign increases the diversity and amount of information available.
Symbolically housed in the oldest and last surviving structure of Los Angeles’ original Chinatown, the Chinese American Museum strives to foster a deeper understanding and appreciation of America’s diverse heritage and the continuing contributions of Chinese Americans.
The Chinese American Museum website is hosted by Media Temple.