Skip to content

Instantly share code, notes, and snippets.

@Stiofan
Last active April 1, 2017 12:26
Show Gist options
  • Save Stiofan/7a90f6d36ea38f42b24da147a96d01fc to your computer and use it in GitHub Desktop.
Save Stiofan/7a90f6d36ea38f42b24da147a96d01fc to your computer and use it in GitHub Desktop.
Associations custom field with images and links
<?php
// replace 'associations' with your html var
add_filter('geodir_custom_field_output_multiselect_var_geodir_associations','_my_association_outputs',10,3);
function _my_association_outputs($html,$location,$cf){
// check we have the post value
global $post;
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) {
if($val=="BBB"){
$html .= '<li><a href="https://wp.org" target="_blank"><img src="http://some-site.con/some-imgae.jpg" /></a></li>';
}elseif($val=="CCC"){
$html .= '<li><a href="https://google.com" target="_blank"><img src="http://some-site.con/some-other-imgae.jpg" /></a></li>';
}else{
$html .= '<li>' . $val . '</li>';
}
}
$html .= '</ul>';
} else {
$html .= __($post->{$cf['htmlvar_name']}, 'geodirectory');
}
$html .= '</div>';
endif;
return $html;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment