donglei3370 2018-12-11 15:46
浏览 67

PHP Dropdown选择echo多个分类法

I have 3 dropdowns that I'm chaining i.e County, City, Area. I need to print all these into every select option as a class so I can use jquery to set up show/hide rules. Currently i just have for example

<option value="thiscounty">This County</option>

what i need is

<option value="thiscounty" class="thiscity thisarea">This County</option>

This is my code

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
}

}

I obviously need to add city and area taxonomies to the foreach loop to then echo these as a class but not sure how to do this as fairly new to php. Any help greatly appriciated.

Cheers

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Stata 面板数据模型选择
    • ¥20 idea运行测试代码报错问题
    • ¥15 网络监控:网络故障告警通知
    • ¥15 django项目运行报编码错误
    • ¥15 请问这个是什么意思?
    • ¥15 STM32驱动继电器
    • ¥15 Windows server update services
    • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
    • ¥15 模糊pid与pid仿真结果几乎一样
    • ¥15 java的GUI的运用