Get Directions link in sidebar widget
This topic contains 15 replies, has 2 voices, and was last updated by Joy 8 years, 8 months ago.
We have moved to a support ticketing system and our forums are now closed.
Open Support Ticket-
AuthorPosts
-
February 21, 2016 at 8:13 am #125395
Hello, I see that this has been requested before and this code will provide a text link that will open up Google Maps for directions:
add_action('geodir_after_detail_page_more_info' , 'buttonmap', 10); function buttonmap(){ global $post, $wp_query, $preview, $geodirectory; $postid = $wp_query->post->ID; $address= geodir_get_post_meta($postid,'post_address',true); //address $e_add = str_replace(' ', '+', $address); // + in space eg road+street+23 $lat= geodir_get_post_meta($postid,'post_latitude',true); //lat $lon= geodir_get_post_meta($postid,'post_longitude',true); //lon //echo $e_add.$lat.$lon; echo "<a href="http://maps.google.com/maps?z=12&t=m&q=loc:".$lat."+".$lon."" target="_blank"> Mostra en Google Maps</a>"; }
However, is it possible to add the address box and the Get Directions button to the sidebar widget – the same that appears on the Maps tab on the listing details? Thank you.
February 22, 2016 at 4:20 pm #125908Hi,
this should do it:
add_action( 'geodir_detail_sidebar_inside', 'sd_map_in_detail_page_sidebar',2); function sd_map_in_detail_page_sidebar() { global $post, $post_images, $video, $special_offers, $related_listing, $geodir_post_detail_fields; $post_id = !empty($post) && isset($post->ID) ? (int)$post->ID : 0; $request_post_id = !empty($_REQUEST['p']) ? (int)$_REQUEST['p'] : 0; $is_backend_preview = (is_single() && !empty($_REQUEST['post_type']) && !empty($_REQUEST['preview']) && !empty($_REQUEST['p'])) && is_super_admin() ? true : false; // skip if preview from backend if ($is_backend_preview && !$post_id > 0 && $request_post_id > 0) { $post = geodir_get_post_info($request_post_id); setup_postdata($post); } $geodir_post_detail_fields = geodir_show_listing_info('detail'); if (geodir_is_page('detail')) { $map_args = array(); $map_args['map_canvas_name'] = 'detail_page_map_canvas'; $map_args['width'] = '300'; $map_args['height'] = '400'; if ($post->post_mapzoom) { $map_args['zoom'] = '' . $post->post_mapzoom . ''; } $map_args['autozoom'] = false; $map_args['child_collapse'] = '0'; $map_args['enable_cat_filters'] = false; $map_args['enable_text_search'] = false; $map_args['enable_post_type_filters'] = false; $map_args['enable_location_filters'] = false; $map_args['enable_jason_on_load'] = true; $map_args['enable_map_direction'] = true; $map_args['map_class_name'] = 'geodir-map-detail-page'; } elseif (geodir_is_page('preview')) { global $map_jason; $map_jason[] = $post->marker_json; $address_latitude = isset($post->post_latitude) ? $post->post_latitude : ''; $address_longitude = isset($post->post_longitude) ? $post->post_longitude : ''; $mapview = isset($post->post_mapview) ? $post->post_mapview : ''; $mapzoom = isset($post->post_mapzoom) ? $post->post_mapzoom : ''; if (!$mapzoom) { $mapzoom = 12; } $map_args = array(); $map_args['map_canvas_name'] = 'preview_map_canvas'; $map_args['width'] = '300'; $map_args['height'] = '400'; $map_args['child_collapse'] = '0'; $map_args['maptype'] = $mapview; $map_args['autozoom'] = false; $map_args['zoom'] = "$mapzoom"; $map_args['latitude'] = $address_latitude; $map_args['longitude'] = $address_longitude; $map_args['enable_cat_filters'] = false; $map_args['enable_text_search'] = false; $map_args['enable_post_type_filters'] = false; $map_args['enable_location_filters'] = false; $map_args['enable_jason_on_load'] = true; $map_args['enable_map_direction'] = true; $map_args['map_class_name'] = 'geodir-map-preview-page'; } if (geodir_is_page('detail') || geodir_is_page('preview')) {?> <div class="sd-map-in-sidebar-detail"><?php geodir_draw_map($map_args);?> </div> <?php } }
Let us know how you went,
Thanks
February 22, 2016 at 8:16 pm #125976Hi Paolo. Thank you but it didn’t work out. It places the map/button on the top of the sidebar and the loading icon just keeps spinning and spinning. I’ve also tried to put the code directly into a php widgets and am getting the following error:
Parse error: syntax error, unexpected ‘}’ in /home/luckywel/public_html/wp-content/plugins/php-code-widget/execphp.php(27) : eval()’d code on line 74
February 23, 2016 at 7:18 pm #126615To make it appear at the bottom of the detail sidebar you need to change the priority used, for example:
from
add_action( 'geodir_detail_sidebar_inside', 'sd_map_in_detail_page_sidebar',2);
to
add_action( 'geodir_detail_sidebar_inside', 'sd_map_in_detail_page_sidebar',10);
If it doesn’t work probably there is an issue with some other code.
We’d need to check you website to let you know. PHP widgets are not a good practice and i don’t think you can stick a function in it.
Let us know,
Thanks
February 23, 2016 at 7:48 pm #126627This reply has been marked as private.February 24, 2016 at 4:50 pm #127095Hi,
the code i gave you works on the child theme I’m building so I’m not sure where the problem could be.
I’ve passed this to Stiofan.
Thanks for your patience,
February 24, 2016 at 5:00 pm #127098Hi,
you just needed to exlude it from GD>Desing>details>hide tabs
Thanks
February 24, 2016 at 5:59 pm #127122Thank you, it cannot be in both the tabs and the sidebar at the same time?
February 24, 2016 at 6:07 pm #127145The function I gave you is to move the map of the tab to the sidebar to have the get direction tool.
You can have it in tab and sidebar if in the sidebar you use the widget.
Thanks
February 24, 2016 at 6:12 pm #127146The widget only shows the map. I am trying to append the text box and the get directions to both the listing tab and a sidebox. Is this possible?
Thank you.
February 24, 2016 at 6:22 pm #127150No it is not.
The get direction part belongs to the tabs map.
You can’t mix it with the widget map. They are 2 different set of functions.
Thanks
February 24, 2016 at 6:34 pm #127155Thank you for explaining that. I have two last concerns:
1. How to disable the mouse scrolling
2. I have a widget that I would like to place BEFORE this map. I’ve moved the map to the end of the details listing, is there a way that my widget can be placed before the map? The widget is set in the “GD Detail Listing” sidebar. I don’t know if they respect the priority settings.February 24, 2016 at 9:19 pm #1273251) have you tried adding a new arg to the map function?
$map_args['scrollwheel'] = false;
2) try increase from 10 to 30:
add_action( 'geodir_detail_sidebar_inside', 'sd_map_in_detail_page_sidebar',30);
Let us know,
Thanks
February 24, 2016 at 9:24 pm #127327This reply has been marked as private.February 24, 2016 at 9:30 pm #127329Hi,
You cannot add the map in between widgets like that. If you want the map in between widgets you must use the map widget.
Thanks
-
AuthorPosts
We have moved to a support ticketing system and our forums are now closed.
Open Support Ticket