我链接了3个下拉列表,即县,市,地区。我需要将所有这些作为类打印到每个选择选项中,以便可以使用jquery设置显示/隐藏规则。目前我仅举个例子
<option value="thiscounty">This County</option>
我需要的是
<option value="thiscounty" class="thiscity thisarea">This County</option>
这是我的代码
if(!function_exists('ct_search_form_select')) {
function ct_search_form_select($name, $taxonomy_name = null) {
global $search_values;
global $ct_options;
$ct_zip_or_post = isset( $ct_options['ct_zip_or_post'] ) ? $ct_options['ct_zip_or_post'] : '';
$ct_city_town_or_village = isset( $ct_options['ct_city_town_or_village'] ) ? $ct_options['ct_city_town_or_village'] : '';
$ct_state_or_area = isset( $ct_options['ct_state_or_area'] ) ? $ct_options['ct_state_or_area'] : '';
$ct_community_neighborhood_or_district = isset( $ct_options['ct_community_neighborhood_or_district'] ) ? $ct_options['ct_community_neighborhood_or_district'] : '';
if(!$taxonomy_name) {
$taxonomy_name = $name;
$tax_label = str_replace('_', ' ', $name);
$tax_name_stripped = str_replace('ct ', '', $tax_label);
if($tax_name_stripped == 'property type') {
$tax_name = __('Property Type', 'contempo');
} elseif($tax_name_stripped == 'county') {
$tax_name = __('County', 'contempo');
} elseif($tax_name_stripped == 'city') {
$tax_name = __('City', 'contempo');
} elseif($tax_name_stripped == 'state' && $ct_state_or_area == 'area') {
$tax_name = __('Area', 'contempo');
} elseif($tax_name_stripped == 'community') {
$tax_name = __('Community', 'contempo');
}
} ?>
<select id="ct_<?php echo esc_html($name); ?>" name="ct_<?php echo esc_html($name); ?>">
<option value="0"><?php echo esc_html(ucfirst($tax_name)); ?></option>
<?php foreach( get_terms($taxonomy_name, 'hide_empty=true') as $t ) : ?>
<?php if ($search_values[$name] == $t->slug) { $selected = 'selected=selected '; } else { $selected = ''; } ?>
<option <?php echo esc_html($selected); ?>value="<?php echo esc_attr($t->slug); ?>"><?php echo esc_html($t->name); ?></option>
<?php endforeach; ?>
</select>
<?php
}
}
我显然需要将城市和区域分类法添加到foreach循环中,然后将它们作为类进行回显,但不确定如何对php相当新。任何帮助都非常有用。
欢呼