Open calcypher opened 10 years ago
Hi. If you post your changes here I'll happily integrate them into the plugin :)
My changes are in two file, includes/shortcodes.php and includes/templates.php. i must write the code here because it's not possible to attach php files here.
in shortcodes.php, i've changed the function "shortcode_wpgeo_mashup":
/**
@return string HTML required to display map. */ if ( ! function_exists( 'shortcode_wpgeo_mashup' ) ) { function shortcode_wpgeo_mashup( $atts, $content = null ) { global $wpgeo;
$wp_geo_options = get_option( 'wp_geo_options' );
$atts = wp_parse_args( $atts, array(
'title' => '', // MODIFIED BY CALCYPHER
'title_link' => '', // MODIFIED BY CALCYPHER
'width' => $wp_geo_options['default_map_width'],
'height' => $wp_geo_options['default_map_height'],
'type' => $wp_geo_options['google_map_type'],
'polylines' => $wp_geo_options['show_polylines'],
'polyline_colour' => $wp_geo_options['polyline_colour'],
'align' => 'none',
'numberposts' => -1,
'posts_per_page' => -1,
'post_type' => null,
'post_status' => 'publish',
'post_ids' => null, // MODIFIED BY CALCYPHER
'orderby' => 'post_date',
'order' => 'DESC',
'markers' => 'large'
) );
if ( ! is_feed() && isset( $wpgeo ) && $wpgeo->show_maps() && $wpgeo->checkGoogleAPIKey() )
return get_wpgeo_map( $atts );
return '';
} add_shortcode( 'wpgeo_mashup', 'shortcode_wpgeo_mashup' ); }
in templates.php, i've changed the function "get_wpgeo_map":
/**
@return string Output. */ function get_wpgeo_map( $query, $options = null ) { global $wpgeo, $wpgeo_map_id;
$wpgeo_map_id++; $id = 'wpgeo_mapid' . $wpgeo_map_id; $wp_geo_options = get_option('wp_geo_options');
$defaults = apply_filters( 'wpgeo_map_default_query_args', array( 'width' => $wp_geo_options['default_map_width'], 'height' => $wp_geo_options['default_map_height'], 'type' => $wp_geo_options['google_map_type'], 'polylines' => $wp_geo_options['show_polylines'], 'polyline_colour' => $wp_geo_options['polyline_colour'], 'align' => 'none', 'numberposts' => -1, 'posts_per_page' => -1, 'post_type' => 'post', 'post_status' => 'publish', 'orderby' => 'post_date', 'order' => 'DESC', 'markers' => 'large', 'offset' => 0, 'category' => null, 'include' => null, 'exclude' => null, 'meta_key' => null, 'meta_value' => null, 'post_mime_type' => null, 'post_parent' => null ) );
// Validate Args $r = wp_parse_args( $query, $defaults ); $r['width'] = wpgeo_css_dimension( $r['width'] ); $r['height'] = wpgeo_css_dimension( $r['height'] );
if ( $r['posts_per_page'] < $r['numberposts'] ) { $r['posts_per_page'] = $r['numberposts']; }
/* MODIFIED BY CALCYPHER - START */ if ($query['post_ids'] != "") $r['post__in'] = explode(',', $query['post_ids']);
$title = ''; if ($query['title'] != null && $query['title'] != "") { if ($query['title_link'] != null && $query['title_link'] != "") { $title = '
'; } else { $title = '$posts = get_posts( $r );
// Map $map = new WPGeoMap( 'id' . $wpgeo_map_id ); $map->set_size( $r['width'], $r['height'] ); $map->set_map_centre( new WPGeo_Coord( $wp_geo_options['default_map_latitude'], $wp_geo_options['default_map_longitude'] ) ); $map->set_map_zoom( $wp_geo_options['default_map_zoom'] ); $map->set_map_type( $r['type'] );
// Points if ( $posts ) { foreach ( $posts as $post ) { $coord = get_wpgeo_post_coord( $post->ID ); if ( $coord->is_valid_coord() ) { $marker = get_post_meta( $post->ID, WPGEO_MARKER_META, true ); if ( empty( $marker ) ) $marker = $r['markers']; $map->add_point( $coord, array( 'icon' => apply_filters( 'wpgeo_marker_icon', $marker, $post, 'template' ), 'title' => get_wpgeo_title( $post->ID ), 'link' => get_permalink( $post ), 'post' => $post ) ); } } }
// Polylines if ( count( $map->points ) > 0 ) { if ( $r['polylines'] == 'Y' ) { $polyline = new WPGeo_Polyline( array( 'color' => $r['polyline_colour'] ) ); foreach ( $map->points as $point ) { $polyline->add_coord( $point->coord ); } $map->add_polyline( $polyline ); } }
$center_coord = $map->get_map_centre();
$wpgeo->maps->add_map( $map ); // MODIFIED BY CALCYPHER return $title.$map->get_map_html( array( 'styles' => array( 'float' => $r['align'] ) ) ); }
feel free to change the code if you think it needs any fix.
Allow 'post_ids' for short code added in https://github.com/benhuson/WP-Geo/commit/e7d3a5115a2e53752c88cbf08f65ab06475886fd
For the 'title_link' attribute, are you using that to link to Google Maps or another custom URL?
it can be every url that you want, not necessary Google Maps.
I've developed the code for 3 new parameters in wpgeo_mashup shortcode:
you can see an example on my site: http://www.teneldeserto.it/2012/08/24/bangkok-wat-arun/ http://www.teneldeserto.it/2012/08/27/thailandia-e-cambogia-2012-itinerario-di-viaggio/
the markers are selected by post ids. if you would like to integrate my code, i can send you my code. It's only some changes in wpgeo's files.