4. Displaying Location and Event Fields
Content Construction Kit content types can be used with the event and/or location modules. You can enable event or location for these content types in the same way as you do with any other content type.
In this example, the location module would add address fields to the contact record. There is no need to create those fields in CCK when the location module will manage the fields and also add mapping and search functionality to them.
If you display the $body value of your content, the location information will be displayed as a part of the default formatted display of the node, and you won't have to do anything else.
If you have chosen to format individual fields, as is being done in this example, you will need to manually add the location fields to your template. You can do this a couple of ways.
The location module has a special function to display a complete formatted address, including a map link, and you can call it from your template, as follows:
<?php print theme('location', $location); ?>If that is still not exactly what you want, you can add the individual location fields to your template instead.
The location fields available look like:
[location] => Array
(
[eid] => 30
[type] => node
[name] => HOME
[street] => 111 First Street
[additional] =>
[city] => Metropolis
[province] => IL
[postal_code] => 60606
[country] => US
[latitude] =>
[longitude] =>
[source] => 0
)Your template might look like this:
<dt><label>Address:</label></dt>
<?php if ($location['name']) : ?>
<dd> <?php print $location['name'] ?> </dd>
<?php endif; ?>
<?php if ($location['street']) : ?>
<dd> <?php print $location['street'] ?> </dd>
<?php endif; ?>
<?php if ($location['additional']) : ?>
<dd> <?php print $location['additional'] ?> </dd>
<?php endif; ?>
<?php
$citystate = ($location['city'] ? $location['city'] .', ' : '') . ($location['province'] ? $location['province'] .' ' : '') . $location['postal_code']; ?>
<?php if ($citystate) : ?>
<dd> <?php print $citystate ?> </dd>
<?php endif; ?>
<?php if ($location['country']) : ?>
<dd> <?php print $location['country'] ?> </dd>
<?php endif; ?>
<?php $maplink = location_map_link($location, 'See map: '); ?>
<?php if ($maplink) : ?>
<dd> <?php print $maplink ?> </dd>
<?php endif; ?>The code above takes advantage of a special function that the location module provides -- location_map_link($location, 'See map:') will create a link to a Google or Yahoo map for the specified location. The creation of the $citystate variable checks whether a city and province exist, and if so add their values plus commas and spaces to format that line of the address. This is a bit more complicated, so you can always just fall back on using the theme_location($location) option and avoid all this trouble!
Similarly, if you have event-enabled this content type, and you are viewing a node that has event information in it, you will see a number of event fields that you can add to your template. The event fields available, and an example of the kind of value they hold, include:
[event_start] => 1147114500
[event_end] => 1147114500
[timezone] => 310
[start_offset] => -21600
[start_format] => 05/08/2006 - 12:55pm
[start_time_format] => 12:55 pm
[end_offset] => -21600
[end_format] => 05/08/2006 - 12:55pm
[end_time_format] => 12:55 pmThey include both fields that hold raw timestamps and fields that have been formatted into recognizable dates and times. To add these values into your template use code like:
<?php print $start_time_format ?>You may have noticed that the CCK fields are formatted differently than the location and event fields. The location and event fields don't use the numeric keys nor the 'view' or 'value' options that the CCK fields use. The location fields are two-level arrays, so the variables you use in your template look like $location['city'], while the event fields are simpler, and you use variables like $event_end.
This should give you a good start on customizing your Content Construction Kit content type. There are other ways to do it as well. Read the included documentation for more information.

Print and Format multiple locations
In my CCK contemplate I placed the following code to render multiple locations for a single node:
<?php foreach ($locations as $location) { ?>
<div class="location_sub">
<?php if ($location['name']) : ?>
<?php print "<dt><h3 class\=\"field-label\"><dd>"; ?>
<?php print $location['name'] ?>
<?php print ":</dd></h3></dt>"; ?>
<?php endif; ?>
<?php if ($location['street']) : ?>
<dd> <?php print $location['street'] ?> </dd>
<?php endif; ?>
<?php if ($location['additional']) : ?>
<dd> <?php print $location['additional'] ?> </dd>
<?php endif; ?>
<?php
$citystate = ($location['city'] ? $location['city'] .', ' : '') . ($location['province'] ? $location['province'] .' ' : '') . $location['postal_code']; ?>
<?php if ($citystate) : ?>
<dd> <?php print $citystate ?> </dd>
<?php endif; ?>
<?php $maplink = location_map_link($location, 'See map: '); ?>
<?php if ($maplink) : ?>
<dd> <?php print $maplink ?> </dd>
<?php endif; ?>
<br />
<?php if ($location['phone']) : ?>
<dd> <span class="field-label">Phone: </span><?php print $location['phone'] ?> </dd>
<?php endif; ?>
<?php if ($location['fax']) : ?>
<dd> <span class="field-label">Fax: </span> <?php print $location['fax'] ?>
<?php endif; ?>
</div>
<br />
<?php } ?>
Country names, not abbreviations
I'm noticing that $location['country'] just prints a two letter symbol of the country, and I can't find any actual Country name output other than using the entire theme function, so this is what I did:
<?phpif($location['country']): print str_replace(array('ca', 'us'), array('Canada', 'United States'), $location['country']); endif;
?>
I just used str_replace to find the 2 country symbols and replace them. I suppose it works okay, but in terms of scaling to other countries, it'd get rather tedious to do this. Maybe I'm just overlooking the Country name output?
You can try
You can try this:
http://drupal.org/node/166232
It worked for me
This didn't work for me in a
This didn't work for me in a contemplate.
What worked was:
<?php$country_names = location_get_iso3166_list();
print $country_names[location['country']] ?>
?>