Apr 08 01
avatar

This plugin allows you to record a location against your posts. For example the country that the post talks about, the event took place in, the location you are writing the post from, etc. Your imagination is the limit…

Some of the key features are:

  • Once a post is tagged with a country the plugin allows flag icons to be added to your blog’s pages with simple additions to your template files.
  • You may also record the latitude & longitude of a location. The enhanced version of the plugin provides multiple ways to display the location using Google mapping.
  • Country icons can be clicked to take the user to posts from that country.
  • A sidebar widget that provides a popup to navigate to posts from a given country.
  • Presents an admin page, under the WordPress Tools menu, to review numbers of posts from each country.

I’m quite pleased with the plugin, so it’s available to share, I hope you enjoy it too. :oops:

post-listing

1. A screenshot showing posts tagged with country flag icons.

The plugin is available as a free download.

All I ask is that you credit the plugin, for example, include a link to this page or maybe add a link to your WordPress blogroll.
Or, perhaps please consider purchasing the enhanced version below…

:star: Why not check out my other WordPress plugins too! :star:

Instructions & Installation

  • Just put the complete un-zipped plugin directory into your WordPress plugin directory (if this doesn’t make sense it probably isn’t something you should be trying :-) ) and activate it.
  • Within the WordPress loop, use this country_tag($post->ID); in your index.php template file to show a post’s country tag.
  • And this country_tag($post->ID, false); in your single.php template file to show the post’s country tag.
  • Note, you’ll need this gobal $post; declaration in your template files too if it’s not already there.
  • The second parameter (the default true, or false) determines if it is a short or long output:
    • Long – Location Australia Australia
    • Short – USA
  • The widget has a single option, one of your WordPress pages. When set to one of your pages a link is shown under the popup list of countries in the widget. Following the link goes to that page – where you might show a list of countries featured on your blog, or a map! A map is easily created with the enhanced version of this plugin.
  • You can also include the same popup list of countries used in the widget on your pages by adding this country_list_countries(); to your theme’s template.
widget-options

2. Countries widget options.

How to Tag a Post with a Country

Using the Location section (you can set the title of this section with the first of the plugin options, see below) of the post writing page. Select the Country you want to tag the post with from the country dropdown. For example, to get a UK flag UK select UK from the dropdown.

The country names provided are the names of the icon files in the directory:

wp-content/plugins/post-country/Flags/

Feel free to add additional flag icon files or remove those you don’t want to see listed in the dropdown.


Premium Version of the Plugin with Mapping

The standard plugin allows Latitude & Longitude to be stored along with the country tag. Google mapping is available with an enhanced version of the plugin available to buy below. An example of the mapping is given here showing dozens of mapped posts and venues.

The enhanced plugin provides several advanced mapping interfaces and features.

  • Within the WordPress post writing interface a sophisticated interface (including geo-location by address, place name, etc.) to create and manage the location associated with posts. This interface is shown in screenshot #3 below.
  • A public map for your blog readers to enjoy that shows all the mapped posts and venues (more details below about the venues feature). An example of the mapping is given here showing dozens of mapped posts and venues. The map is automatically inserted by the plugin on any page or post with <!-- adventure-map -->.
  • Show a location map on a post page (when the post has location data). Include a post map with the shortcode [post_map] and optionally set the map-type to ROADMAP, SATELLITE, HYBRID, or the default TERRAIN and zoom level (default 11) with [post_map type="SATELLITE" zoom="14"]. Please see Post Locations below for more options and functionality.
  • The plugin remembers the last map-type shown (using a cookie).
  • Several markers are used on the mapping, the default colours are:
    1. Posts are shown with a blue marker – post-marker.
    2. Posts with GPX data are shown with a purple marker – post-marker.
    3. Named waypoints in GPX tracks are shown with a green marker – waypoint.
    4. Venues are shown with a red marker – venue-marker.
    5. Additional maps embedded within posts showing other locations are shown with a green marker – additional-marker.
    6. When creating location data new locations are shown with a yellow marker – new-marker.
  • In addition to the default markers, there are a number of custom markers included. Add to these as you like, the new markers go in the plugin’s markers directory. There’s even an included Photoshop template (.PSD). The included markers are:
    markermarkermarkermarkermarkermarkermarkermarkermarkermarkermarkermarkermarkermarkermarkermarker
  • A simple yet powerful mechanism to allow uploaded GPX files (e.g. from a GPS enabled device) to be automatically represented with Google mapping showing the trace of a route. These routes may also be accompanied with a graph showing elevation along the route.
  • A number of template tags are provided to optionally enhance your WordPress theme:
    1. To including linked country icons: country_tag($post_ID, $short=true, $prefix='Location ', $size=15, $echo=true);
    2. To include a popup list of countries: country_list_countries();
    3. Location map links: get_map_link($anchor_text, $post_ID='');
    4. Venues button: the_map_sidebar_link($before_HTML, $after_HTML);
    5. Show a link to all venues: get_venues_link();
      Use this template function or have the plugin automatically include a link on any page of post with <!-- venues-link -->.

The plugin has several advantages over other mapping plugins. For example, it doesn’t unduly load your web server, making full use of the power of the user’s browser. This also makes content more interactive, for example hovering over elevation graphs shows the data at that point of the graph dynamically.

The following screenshots give a flavour of the plugin’s rich capabilities. The size, position, etc. of each map on your pages is customisable using CSS settings (defaults are initially provided), please refer to the options screenshot #13 below.

Post Editing

The following screenshot shows the location editing interface within the WordPress editor. As well as adding a country flag attribute to posts, add Latitude & Longitude either manually (click the location on the map) or use geo-location (address, place name, etc.). The new location marker (new-marker) can be dragged around the map to achieve an accurate position.

The location’s map marker can also be changed from the default using the marker drop-down list.

The multiple location plugin option (see screenshot #13 below) allows multiple locations to recorded for each post. When enabled the add and remove buttons are shown. Click the arrow icon to set the focus of geo-location, dragging the new location marker, and map clicks.

location-box

3. The post editing Location section.

The Country column of the post listing (screenshot #1 above) is enhanced when location data is given. Posts with location data will have Geo and an indication of the quality of the data:

  • Geo: geo-data-ok – the Latitude & Longitude are OK.
  • Geo: geo-data-incomplete – only one Latitude or Longitude value is provided.
  • Geo: geo-data-stopped – the Latitude & Longitude are OK, but the administrator has blocked plotting.

Multiple Markers at Maximum Zoom

A limitation of Google mapping is that each map-type has a maximum level of zoom. For example, the most limited level of zoom is often found with the TERRAIN style of map. Switching to SATELLITE may allow a higher level of zooming, especially in popular urban areas like cities. However, regardless of map-type, sooner or later it will be impossible to zoom the mapping any further. At this point if you have multiple locations mapped the clustering of the markers will be impossible un-cluster. This plugin deals with this problem by offering a tabbed popup, one tab for each location. Just click on the cluster to see the tabs. (The popup will be un-tabbed when clicking on a single marker.)

multiple-locations

4. Multiple location tabs.

This example also shows how feature image thumbnails can be optionally included in the popup summary about a location (see the display icons option in screenshot #13 below).

Custom Markers

Alongside the default markers described above there are three ways to set custom markers:

  1. Venues may use their country flag as their map marker (see options screenshot #13 below).
  2. Custom markers can be set for individual posts (see screenshot #3 above).
  3. Or you may set a custom marker for a post category. The enhanced post category editing page provides this function.
edit-post-categories

5. The post category editing page.

edit-post-categories

6. List of categories showing custom markers.

GPX Tracks & Elevation Graphs

Upload GPX files, say from your GPS device, to automatically show the tracks.

gpx-file-trace

7. An uploaded GPX file automatically shown with mapping.

The GPX trace will show any named waypoints with a small green marker – waypoint. If the post that the GPX is shown in has location data the location will be shown with a purple marker – post-marker.

Accompanying maps of GPX tracks, graphing of the elevation along the path of the track may be displayed. Graphs are built dynamically by the user’s browser using Google Charts (so unlike some other plugins they do not cause lots of PHP processing on your server or blow PHP’s memory limits). Here’s an example of the graph that accompanies the track above.

gpx-elevation-graph

8. A graph of elevation associated with an uploaded GPX file.

GPX files may be uploaded using the normal WordPress media upload and then embedded within a post. For example, the following simple markup will be automatically presented with a Google map showing the route described by the GPX file.

<a href='http://your-domain/path/file.gpx'>GPX Data</a>

If enabled (see options below) an elevation graph will be automatically included. However, if you want to suppress the elevation graph for a specific GPX track include elevation='off' in the markup. For example:

<a href='http://your-domain/path/file.gpx' elevation='off'>GPX Data</a>

Post Locations

Posts can show their location on a map. The map is easily embedded within the post with the shortcode [post_map] and you can optionally set the map-type to ROADMAP, SATELLITE, HYBRID, or the default TERRAIN and the zoom level (default 11). For example, [post_map type="SATELLITE" zoom="14"] will show the location associated with this post on a satellite map at zoom level 14.

The shortcode can also be inserted using quicktag buttons. In the WordPress HTML post editor the button is button and in the Visual editor the button is .

post-location-map

9. Example post location map.

There are several more additional attributes that can be added to the shortcode to show any number of other locations within posts. These are: location – a latitude & longitude comma separated pair; loc_name – a name for the new location; link – override the Include link to Venues map option; style – override the post_map CSS option; and current – show the current location. For example you might show a place of interest with:

[post_map zoom='16' type='SATELLITE' location='54.339,-2.743' loc_name='Playing Fields']

location-map

10. Example additional location map.

Show your current location (if your browser allows it) with:

[post_map zoom='16' type='ROADMAP' current='on' style='width: 400px; height: 200px; border: 1px solid #ddd;']

Venues

11. Show your current location - if your browser allows it!

Provide a table of locations associated with this post using the shortcode [locations_table]. There is one optional parameter title. This is the title to display before the table of locations (default is Venues or your customised name).

Geo-tagged Photo Mapping

The plugin also supports mapping of photographs (JPG images only) with geo-tagging EXIF data. The EXIF location data may have been added to the photo’s meta-data automatically when the picture was taken by a GPS enabled camera, manually, or photo organising software such as Adobe’s Lightroom or Apple’s iPhoto or Aperture.

geo-tagged-photos

12. Mapping showing geo-tagged photos.

Note, a default WordPress installation does not preserve EXIF data when uploading and scaling images. Therefore the plugin will not have access to location meta-data in photos uploaded before the plugin was installed and the Save image location data option was set. Photos that have had their geo-tagged location data successfully read will show with a Geo Tag in the WordPress media library list as shown.

An example of the WordPress Media library list showing geo-tagged images

An example of the WordPress Media library list showing geo-tagged images

Main Location Map & Options

Using the enhanced mapping features within a post is easy and highly flexible. Using the mapping is explained more here.

Mapping of all tagged posts (and Venues, see below) can be presented to your users on a nominated page. (The blog administrator can elect to not display the location of specific posts even when latitude & longitude values have been supplied.) Here’s an example location map. The page used to display the map is defined on the plugin options page. That page should have the following simple code within its text to show the map.

<!-- adventure-map -->

Note, the options page also provides a field to enter the CSS for the map canvas. It is essential that this sets, as a minimum, the size of the canvas. To kick-off try something like:

width: 600px; height: 450px; border: 1px solid #ddd; margin: 5px;

options

13. Options.

There are seven sets of options:

  1. Plugin – general plugin options including the title of the editing box, if the map should initially be shown or hidden on the WordPress post editing page, the scope of searches, etc.
  2. Venues Map Page – the page and style used to display the main venues map.
  3. Post Map – how maps are embedded, with a shortcode, in posts.
  4. Images – options to allow and show geo-tagged images to be mapped.
  5. GPX Processing – control processing of GPX files attached to posts.
  6. Elevation Chart – control elevation charts associated with attached GPX files.
  7. Markers – define the colours of the default markers used by each type of map, and also enable custom markers for venues and posts.

Geo RSS Feed

The Venues Map Page options allow configuration of whether location data, for posts and/or venues, are included in the standards compliant Geo RSS feed generated by the plugin. (Note, add ?feed=venues to your blog’s main URL to access the location RSS feed. You may wish to use this, for example, to submit geo content to Google as a geo site map.)

Venues

In addition to tagging posts with country and latitude & longitude for mapping the enhanced plugin provides a special type of post – Venue. These are great for recording specific details about specific locations. For example, a page of information for each country, or a page of details (e.g. pubs, clubs, and hotels) about a particular city. Venues are a blend between standard WordPress pages and posts. Venues are accessed from the new Venues menu. (Note that the list of countries moves with the enhanced version of the plugin from the WordPress Tools menu to the Venues menu.)

venues-menu

14. The new Venues menu.


Buy the Enhanced Plugin with Google Mapping

Buy the enhanced Post Country Plugin here for an insanely cheap price!

Post Country Plugin

[SKU23496] £19.50 (P&P £0.00)

Buy the plugin and I will provide free updates forever as the plugin gets more and more features…

FAQ

  • Are Google Map Controls failing to render properly?
  • Often WordPress themes makes a common mistake that stops Google mapping controls from being drawn properly. This is because the theme forces sizing for all images. I have suggested a fix for this with an alteration like the one I recommend on this Stack Overflow post. Just add the suggested CSS rule to your theme’s style.css, however, even then some themes have CSS rules that take precedence. In these cases I suggest you either get stuck in to working out the CSS in your theme, or you could try applying a sledgehammer (!important)...
    .gmnoprint img { max-width: none !important; }
  • Post editing only showing a single marker?
  • Make sure you have enabled the inclusion of Posts and/or Venues in the Venues Feed. These are two separate checkbox options available on the plugin's settings page, under the Venues Map Page section.
  • Are your geo-tagged photos failing to show on post maps?
  • Unfortunately some geo-tagged photos are not recognised by the underlying PHP read_exif_data function. This bug is trapped to allow the image to upload properly, but the latitude and longitude data for the image won't be captured by this plugin. You will know if your image has a faulty set of geo-tagging data as the WordPress media list will not show the image as geo-tagged. As soon as there is a fix for this PHP bug - either in a later release of PHP or by using some other geo-tagging information extraction mechanism - a new version of the plugin will be issued to all users.
  • Can I add GPS location data to JPG images manually?
  • If you digital camera (or smartphone) does not have the ability to tag photos with GPS location data it is possible to manually add the location meta data yourself using photo manipulation software like Adobe Lightroom. There other free tools too like Google’s Picasa (although I haven’t tried any of the free tools). Note, GPS data is embedded inside the JPG image file’s meta data.

Version History

Enhanced Plugin:

  • 18 Directions.
  • 17 – New short code ([locations_table]) to provide a table of locations.
  • 16 – Allow a custom name for “Venues”, e.g. “Locations”.
  • 15 – Post maps can show geo-tagged photo locations for all JPG images attached to a post.
  • 14 – Added option to center administration map on current location.
  • 13 – Include option to show featured image thumbnails in venue information bubbles.
  • 12 – Allow multiple markers at the exact same location.
  • 11 – Multiple locations per post.
  • 10 – Finished custom marker release – venues can use flags, posts and categories can have custom markers.
  • 9 – Options to select marker colours.
  • 8 – Include Venues (and/or Pages) in search results.
  • 7 – Added drag-zoom feature to venues page.
  • 6 – Internationalisation.
  • 5 – Option to include a map within a post page.
  • 4 – Mapping & GPX tracks.
  • 3 – Venue post-type to record location, beta, facts, links, etc. for given locations.

Standard Plugin:

  • 2 – Version without mapping and new Enhanced version with mapping.
  • 1 – Initial version.
With regret comments are closed on this post to avoid being deluged with “how to” queries and not genuine issues with the plugin. So, if you want support or advice use the feedback link. But please note I will ask for a donation before I’ll look at “how to” questions, I can’t teach PHP programming for free.

Series - WordPress Plug-ins

  1. Image Link WordPress Plug-in
  2. Last Year WordPress Sidebar Widget Plugin
  3. Simple Archive Plugin
  4. Avatars Plugin
  5. WordPress Post Country Plugin
    (with premium Google Mapping)
  6. Notices Ticker Plugin
  7. Comments with Avatars
  8. Simple WordPress Twitter Plugin
  9. WordPress Post Grouping Plugin
  10. WordPress Mapping Plugin