Custom fields in More Tab different html if 1 or 2+
This topic contains 6 replies, has 4 voices, and was last updated by ian bran 6 years, 5 months ago.
We have moved to a support ticketing system and our forums are now closed.
Open Support TicketTagged: snippet
-
AuthorPosts
-
July 12, 2018 at 6:15 pm #438180
Hello, this is hardly a bug, but it makes hard to affect the css of checkbox custom fields.
When in a group of checkbox only 1 is selected, the html is:
<div class="geodir_more_info"> CF1 </div>
When 2 or more are checked, the output is:
<div class="geodir_more_info"> <ul> <li> CF1 </li> <li> CF2 </li> </div>
It would be great if all CF’s are on an UL with one LI (even if the CF is only one), so I can be able to affect all the LI’s.
Please take a look at the screenshot.
Thank you for your time
July 12, 2018 at 9:30 pm #438194Thanks for pointing that out. We will take a look at improving that.
July 13, 2018 at 12:05 am #438200Thank you for receiving this well! I hope I was clear.
I spent lot of time designing and coding and hit a wall there 🙁
July 21, 2018 at 12:45 pm #439255Hello Ian,
Normally UL > LI used when there are more then one list items to display, but for one item we not used it.
If you want to display UL LI for single item as well then just add following code snippet./* * Add UL to single item for multiselect */ function _gd_custom_multiselect_list_item($html,$location,$cf,$p=''){ // check we have the post value if(is_int($p)){$post = geodir_get_post_info($p);} else{ global $post;} if(!is_array($cf) && $cf!=''){ $cf = geodir_get_field_infoby('htmlvar_name', $cf, $post->post_type); if(!$cf){return NULL;} } $html_var = $cf['htmlvar_name']; // Check if there is a location specific filter. if(has_filter("geodir_custom_field_output_multiselect_loc_{$location}")){ /** * Filter the multiselect html by location. * * @param string $html The html to filter. * @param array $cf The custom field array. * @since 1.6.6 */ $html = apply_filters("geodir_custom_field_output_multiselect_loc_{$location}",$html,$cf); } // Check if there is a custom field specific filter. if(has_filter("geodir_custom_field_output_multiselect_var_{$html_var}")){ /** * Filter the multiselect html by individual custom field. * * @param string $html The html to filter. * @param string $location The location to output the html. * @param array $cf The custom field array. * @since 1.6.6 */ $html = apply_filters("geodir_custom_field_output_multiselect_var_{$html_var}",$html,$location,$cf); } // Check if there is a custom field key specific filter. if(has_filter("geodir_custom_field_output_multiselect_key_{$cf['field_type_key']}")){ /** * Filter the multiselect html by field type key. * * @param string $html The html to filter. * @param string $location The location to output the html. * @param array $cf The custom field array. * @since 1.6.6 */ $html = apply_filters("geodir_custom_field_output_multiselect_key_{$cf['field_type_key']}",$html,$location,$cf); } // If not html then we run the standard output. if(empty($html)){ if (!empty($post->{$cf['htmlvar_name']})): if (is_array($post->{$cf['htmlvar_name']})) { $post->{$cf['htmlvar_name']} = implode(', ', $post->{$cf['htmlvar_name']}); } $field_icon = geodir_field_icon_proccess($cf); if (strpos($field_icon, 'http') !== false) { $field_icon_af = ''; } elseif ($field_icon == '') { $field_icon_af = ''; } else { $field_icon_af = $field_icon; $field_icon = ''; } $field_values = explode(',', trim($post->{$cf['htmlvar_name']}, ",")); if(is_array($field_values)){ $field_values = array_map('trim', $field_values); } $option_values = array(); if (!empty($cf['option_values'])) { $cf_option_values = geodir_string_values_to_options(stripslashes_deep($cf['option_values']), true); if (!empty($cf_option_values)) { foreach ($cf_option_values as $cf_option_value) { if (isset($cf_option_value['value']) && in_array($cf_option_value['value'], $field_values)) { $option_values[] = $cf_option_value['label']; } } } } $html = '<div class="geodir_more_info ' . $cf['css_class'] . ' ' . $cf['htmlvar_name'] . '" style="clear:both;"><span class="geodir-i-select" style="' . $field_icon . '">' . $field_icon_af; $html .= (trim($cf['site_title'])) ? __($cf['site_title'], 'geodirectory') . ': ' : ''; $html .= '</span>'; if (count($option_values) > 1) { $html .= '<ul>'; foreach ($option_values as $val) { $html .= '<li class="_gd_multi-' . sanitize_html_class( sanitize_title_with_dashes( $val ) ) . '">' . $val . '</li>'; } $html .= '</ul>'; } else { $val = __($post->{$cf['htmlvar_name']}, 'geodirectory'); $html .= '<ul><li class="_gd_multi-' . sanitize_html_class( sanitize_title_with_dashes( $val ) ) . '">' . $val . '</li></ul>'; } $html .= '</div>'; endif; } return $html; } add_filter('geodir_custom_field_output_multiselect','_gd_custom_multiselect_list_item',9,3);
Thanks,
KiranJuly 24, 2018 at 3:12 pm #439572Thank you Kiran,
I updated that I found a solution but now I see it was not posted, my bad.
Anyway, your code is better.
Thank you so much for the great code!Best
July 31, 2018 at 3:55 pm #440615I have made this change in the code to always use li in GDv2
Thanks,
Stiofan
July 31, 2018 at 4:46 pm #440634Awesome, thank you.
Regards,
Ian -
AuthorPosts
We have moved to a support ticketing system and our forums are now closed.
Open Support Ticket