コード例 #1
0
 /**
  * List located posts by area template tag.
  *
  * Returns an HTML list of all located posts by country and state. May try to look up 
  * this information when absent.
  *
  * @since 1.2
  * @link http://github.com/cyberhobo/wordpress-geo-mashup/wiki/Tag-Reference#list-located-posts-by-area
  *
  * @param string|array $args Template tag arguments.
  * @return string List HTML.
  */
 public static function list_located_posts_by_area($args)
 {
     static $instance_count = 1;
     $args = wp_parse_args($args);
     if ($instance_count > 1) {
         $id_suffix = '-' . $instance_count;
     } else {
         $id_suffix = '';
     }
     $list_html = '<div id="gm-area-list' . $id_suffix . '" class="gm-area-list">';
     $countries = GeoMashupDB::get_distinct_located_values('country_code', array('object_name' => 'post'));
     $country_count = count($countries);
     $country_heading = '';
     foreach ($countries as $country) {
         if ($country_count > 1) {
             $country_name = GeoMashupDB::get_administrative_name($country->country_code);
             $country_name = $country_name ? $country_name : $country->country_code;
             $country_heading = '<h3 id="' . $country->country_code . $id_suffix . '">' . $country_name . '</h3>';
         }
         $states = GeoMashupDB::get_distinct_located_values('admin_code', array('country_code' => $country->country_code, 'object_name' => 'post'));
         if (empty($states)) {
             $states = array((object) array('admin_code' => null));
         }
         foreach ($states as $state) {
             $location_query = array('object_name' => 'post', 'country_code' => $country->country_code, 'admin_code' => $state->admin_code, 'sort' => 'post_title');
             $post_locations = GeoMashupDB::get_object_locations($location_query);
             if (count($post_locations) > 0) {
                 if (!empty($country_heading)) {
                     $list_html .= $country_heading;
                     $country_heading = '';
                 }
                 if (null != $states[0]->admin_code) {
                     $state_name = GeoMashupDB::get_administrative_name($country->country_code, $state->admin_code);
                     $state_name = $state_name ? $state_name : $state->admin_code;
                     $list_html .= '<h4 id="' . $country->country_code . '-' . $state->admin_code . $id_suffix . '">' . $state_name . '</h4>';
                 }
                 $list_html .= '<ul class="gm-index-posts">';
                 foreach ($post_locations as $post_location) {
                     $list_html .= '<li><a href="' . get_permalink($post_location->object_id) . '">' . $post_location->label . '</a>';
                     if (isset($args['include_address']) && $args['include_address'] == 'true') {
                         $list_html .= '<p>' . $post_location->address . '</p>';
                     }
                     $list_html .= '</li>';
                 }
                 $list_html .= '</ul>';
             }
         }
     }
     $list_html .= '</div>';
     return $list_html;
 }