Modfying map bubble content
This topic contains 3 replies, has 2 voices, and was last updated by Kor 8 years, 8 months ago.
We have moved to a support ticketing system and our forums are now closed.
Open Support Ticket-
AuthorPosts
-
August 9, 2016 at 1:42 am #243575
Hello.
I’d be grateful if someone could offer some advice please.
I’m trying to modify the content of the map bubble content to include the city and postcode and have read a few posts here about using the following in the theme functions.
add_filter('geodir_custom_infowindow_html' , 'geodir_get_custom_infowindow_html', 10,3) ; function geodir_get_custom_infowindow_html($html , $postinfo_obj, $post_preview = '') { return 'Here u can copy content of geodir_get_infowindow_html function and can make necessary changes in html '; }
However, I’m not sure what code needs to be copied to “Here u can copy content of…“. I’ve found the function
geodir_get_infowindow_html
, but was wondering if the whole block of code from the opening line:
if (!function_exists('geodir_get_infowindow_html')) {
to the end of the function (just before the start of the next function)
if (!function_exists('geodir_new_post_default_status')) {
needs to be copied please?
Thanks for your time.
Ash
August 9, 2016 at 10:57 am #243755Hi Ash,
You can start making your modifications following the code below.
add_filter('geodir_custom_infowindow_html' , 'geodir_get_custom_infowindow_html', 10,3) ; function geodir_get_custom_infowindow_html($html , $postinfo_obj, $post_preview = '') { global $preview, $gd_session; $srcharr = array("'", "/", "-", '"', '\'); $replarr = array("′", "⁄", "–", "“", ''); if ($gd_session->get('listing') && isset($post_preview) && $post_preview != '') { $ID = ''; $plink = ''; if (isset($postinfo_obj->pid)) { $ID = $postinfo_obj->pid; $plink = get_permalink($ID); } $title = str_replace($srcharr, $replarr, ($postinfo_obj->post_title)); $lat = $postinfo_obj->post_latitude; $lng = $postinfo_obj->post_longitude; $address = str_replace($srcharr, $replarr, ($postinfo_obj->post_address)); $contact = str_replace($srcharr, $replarr, ($postinfo_obj->geodir_contact)); $timing = str_replace($srcharr, $replarr, ($postinfo_obj->geodir_timing)); } else { $ID = $postinfo_obj->post_id; $title = str_replace($srcharr, $replarr, htmlentities($postinfo_obj->post_title, ENT_COMPAT, 'UTF-8')); // fix by Stiofan $plink = get_permalink($ID); $lat = htmlentities(geodir_get_post_meta($ID, 'post_latitude', true)); $lng = htmlentities(geodir_get_post_meta($ID, 'post_longitude', true)); $address = str_replace($srcharr, $replarr, htmlentities(geodir_get_post_meta($ID, 'post_address', true), ENT_COMPAT, 'UTF-8')); // fix by Stiofan $contact = str_replace($srcharr, $replarr, htmlentities(geodir_get_post_meta($ID, 'geodir_contact', true), ENT_COMPAT, 'UTF-8')); $timing = str_replace($srcharr, $replarr, (geodir_get_post_meta($ID, 'geodir_timing', true))); } // filter field as per price package global $geodir_addon_list; if (isset($geodir_addon_list['geodir_payment_manager']) && $geodir_addon_list['geodir_payment_manager'] == 'yes') { $post_type = get_post_type($ID); $package_id = isset($postinfo_obj->package_id) && $postinfo_obj->package_id ? $postinfo_obj->package_id : NULL; $field_name = 'geodir_contact'; if (!check_field_visibility($package_id, $field_name, $post_type)) { $contact = ''; } $field_name = 'geodir_timing'; if (!check_field_visibility($package_id, $field_name, $post_type)) { $timing = ''; } } if ($lat && $lng) { ob_start(); ?> <div class="gd-bubble" style=""> <div class="gd-bubble-inside"> <?php $comment_count = ''; $rating_star = ''; if ($ID != '') { $rating_star = ''; $comment_count = geodir_get_review_count_total($ID); if (!$preview) { $post_avgratings = geodir_get_post_rating($ID); $rating_star = geodir_get_rating_stars($post_avgratings, $ID, false); /** * Filter to change rating stars * * You can use this filter to change Rating stars. * * @since 1.0.0 * @package GeoDirectory * @param string $rating_star Rating stars. * @param float $post_avgratings Average ratings of the post. * @param int $ID The post ID. */ $rating_star = apply_filters('geodir_review_rating_stars_on_infowindow', $rating_star, $post_avgratings, $ID); } } ?> <div class="geodir-bubble_desc"> <h4> <a href="<?php if ($plink != '') { echo $plink; } else { echo 'javascript:void(0);'; } ?>"><?php echo $title; ?></a> </h4> <?php if ($gd_session->get('listing') && isset($post_preview) && $post_preview != '') { $post_images = array(); if (!empty($postinfo_obj->post_images)) { $post_images = explode(",", $postinfo_obj->post_images); } if (!empty($post_images)) { ?> <div class="geodir-bubble_image"><a href="<?php if ($plink != '') { echo $plink; } else { echo 'javascript:void(0);'; } ?>"><img alt="bubble image" style="max-height:50px;" src="<?php echo $post_images[0]; ?>"/></a></div> <?php }else{ echo '<div class="geodir-bubble_image"></div>'; } } else { if ($image = geodir_show_featured_image($ID, 'widget-thumb', true, false, $postinfo_obj->featured_image)) { ?> <div class="geodir-bubble_image"><a href="<?php echo $plink; ?>"><?php echo $image; ?></a></div> <?php }else{ echo '<div class="geodir-bubble_image"></div>'; } } ?> <div class="geodir-bubble-meta-side"> <?php /** * Fires before the meta info in the map info window. * * This can be used to add more info to the map info window before the normal meta info. * * @since 1.5.4 * @param int $ID The post id. * @param object $postinfo_obj The posts info as an object. * @param bool|string $post_preview True if currently in post preview page. Empty string if not. * */ do_action('geodir_infowindow_meta_before', $ID, $postinfo_obj, $post_preview); ?> <span class="geodir_address"><i class="fa fa-home"></i> <?php echo $address; ?></span> <?php if ($contact) { ?><span class="geodir_contact"><i class="fa fa-phone"></i> <?php $tel_link = apply_filters('geodir_map_bubble_tel_linkable', false); if ($tel_link) { ?> <a href="tel:<?php echo preg_replace('/[^0-9+]/', '', $contact); ?>"><?php echo stripslashes($contact); ?></a> <?php } else { echo $contact; } ?> </span><?php } ?> <?php if ($timing) { ?><span class="geodir_timing"><i class="fa fa-clock-o"></i> <?php echo $timing; ?></span><?php } /** * Fires after the meta info in the map info window. * * This can be used to add more info to the map info window after the normal meta info. * * @since 1.4.2 * @param object $postinfo_obj The posts info as an object. * @param bool|string $post_preview True if currently in post preview page. Empty string if not. * */ do_action('geodir_infowindow_meta_after',$postinfo_obj,$post_preview ); ?> </div> <?php if ($ID) { $post_author = isset($postinfo_obj->post_author) ? $postinfo_obj->post_author : get_post_field('post_author', $ID); ?> <div class="geodir-bubble-meta-fade"></div> <div class="geodir-bubble-meta-bottom"> <span class="geodir-bubble-rating"><?php echo $rating_star;?></span> <span class="geodir-bubble-fav"><?php echo geodir_favourite_html($post_author, $ID);?></span> <span class="geodir-bubble-reviews"><a href="<?php echo get_comments_link($ID); ?>" class="geodir-pcomments"><i class="fa fa-comments"></i> <?php echo get_comments_number($ID); ?> </a></span> </div> <?php } ?> </div> </div> </div> <?php $html = ob_get_clean(); /** * Filter to change infowindow html * * You can use this filter to change infowindow html. * * @since 1.0.0 * @package GeoDirectory * @param string $html Infowindow html. * @param object $postinfo_obj The Post object. * @param bool|string $post_preview Is this a post preview? */ return $html; } }
August 9, 2016 at 8:46 pm #244107Hello Kor Chung
Thank you kindly for your time and assisitance as it’s most appreciated. The code you posted works perfectly.
For anyone looking to add a city and postcode to the map bubble, this is what I did (I’m not an experienced coder, but it works ok for me).
I slightly modified the code that Kor Chung kindly provided, then added it to my functions.php file.
Specifically, I replaced:
$address = str_replace($srcharr, $replarr, htmlentities(geodir_get_post_meta($ID, 'post_address', true), ENT_COMPAT, 'UTF-8')); // fix by Stiofan
With:
$address = str_replace($srcharr, $replarr, htmlentities(geodir_get_post_meta($ID, 'post_address', true), ENT_COMPAT, 'UTF-8')); // fix by Stiofan $address_city = str_replace($srcharr, $replarr, htmlentities(geodir_get_post_meta($ID, 'post_city', true), ENT_COMPAT, 'UTF-8')); $address_zip = str_replace($srcharr, $replarr, htmlentities(geodir_get_post_meta($ID, 'post_zip', true), ENT_COMPAT, 'UTF-8'));
And replaced:
<span class="geodir_address"><i class="fa fa-home"></i> <?php echo $address; ?></span>
With:
<span class="geodir_address"><i class="fa fa-home"></i> <?php echo $address . ", " . $address_city . ", " . $address_zip; ?></span>
Regards
Ash
August 10, 2016 at 2:04 am #244237Hi Ash,
Glad that helped and thanks for sharing.
-
AuthorPosts
We have moved to a support ticketing system and our forums are now closed.
Open Support Ticket