在PHP中,我可以在此代码中将所有1000,2000,3000格式更改为1K,2K,3K格式

时间:2014-02-21 08:29:06

标签: php

我有0个PHP编码经验,但我需要更改此代码以显示1k,2k,3k等...,这里是完整的代码:

if (!function_exists('get_theme_currency')) {
function get_theme_currency()
{
    $currency = get_option('theme_currency_sign');
    if (!empty($currency)) {
        return $currency;
    }
    return __('$', 'framework');
}
if (!function_exists('get_property_price')) {
function get_property_price()
{
    global $post;
    $price_digits = doubleval(get_post_meta($post->ID, 'REAL_HOMES_property_price', true));
    if ($price_digits) {
        $currency            = get_theme_currency();
        $price_post_fix      = get_post_meta($post->ID, 'REAL_HOMES_property_price_postfix', true);
        $decimals            = intval(get_option('theme_decimals'));
        $decimal_point       = get_option('theme_dec_point');
        $thousands_separator = get_option('theme_thousands_sep');
        $currency_position   = get_option('theme_currency_position');
        $formatted_price     = number_format($price_digits, $decimals, $decimal_point, $thousands_separator);
        if ($currency_position == 'after') {
            return $formatted_price . $currency . ' ' . $price_post_fix;
        } else {
            return $currency . $formatted_price . ' ' . $price_post_fix;
        }
    } else {
        return __('NA', 'framework');
    }
}
if (!function_exists('property_price')) {
function property_price()
{
    echo get_property_price();
}
if (!function_exists('get_custom_price')) {
function get_custom_price($amount)
{
    $amount = doubleval($amount);
    if ($amount) {
        $currency            = get_theme_currency();
        $decimals            = intval(get_option('theme_decimals'));
        $decimal_point       = get_option('theme_dec_point');
        $thousands_separator = get_option('theme_thousands_sep');
        $currency_position   = get_option('theme_currency_position');
        $formatted_price     = number_format($amount, $decimals, $decimal_point, $thousands_separator);
        if ($currency_position == 'after') {
            return $formatted_price . $currency;
        } else {
            return $currency . $formatted_price;
        }
    } else {
        return __('NA', 'framework');
    }
}
if (!function_exists('advance_location_options')) {
function advance_location_options($taxonomy_name)
{
    $taxonomy_terms = get_terms($taxonomy_name, array(
        'hide_empty' => false,
        'parent' => 0
    ));
    $searched_term  = '';
    if ($taxonomy_name == 'property-city') {
        if (!empty($_GET['location'])) {
            $searched_term = $_GET['location'];
        }
    }
    generate_hirarchical_options($taxonomy_name, $taxonomy_terms, $searched_term);
    if ($searched_term == 'any' || empty($searched_term)) {
        echo '<option value="any" selected="selected">' . __('Any', 'framework') . '</option>';
    } else {
        echo '<option value="any">' . __('Any', 'framework') . '</option>';
    }
}
if (!function_exists('min_prices_list')) {
function min_prices_list()
{
    $min_price_array      = array(
        1000,
        5000,
        10000,
        50000,
        100000,
        200000,
        300000,
        400000,
        500000,
        600000,
        700000,
        800000,
        900000,
        1000000,
        1500000,
        2000000,
        2500000,
        5000000
    );
    $minimum_price_values = get_option('theme_minimum_price_values');
    if (!empty($minimum_price_values)) {
        $min_prices_string_array = explode(',', $minimum_price_values);
        if (is_array($min_prices_string_array) && !empty($min_prices_string_array)) {
            $new_min_prices_array = array();
            foreach ($min_prices_string_array as $string_price) {
                $integer_price = doubleval($string_price);
                if ($integer_price > 1) {
                    $new_min_prices_array[] = $integer_price;
                }
            }
            if (!empty($new_min_prices_array)) {
                $min_price_array = $new_min_prices_array;
            }
        }
    }
    $minimum_price = '';
    if (isset($_GET['min-price'])) {
        $minimum_price = doubleval($_GET['min-price']);
    }
    if (!empty($min_price_array)) {
        foreach ($min_price_array as $price) {
            if ($minimum_price == $price) {
                echo '<option value="' . $price . '" selected="selected">' . get_custom_price($price) . '</option>';
            } else {
                echo '<option value="' . $price . '">' . get_custom_price($price) . '</option>';
            }
        }
    }
    if ($minimum_price == 'any' || empty($minimum_price)) {
        echo '<option value="any" selected="selected">' . __('Any', 'framework') . '</option>';
    } else {
        echo '<option value="any">' . __('Any', 'framework') . '</option>';
    }
}
if (!function_exists('max_prices_list')) {
function max_prices_list()
{
    $max_price_array      = array(
        5000,
        10000,
        50000,
        100000,
        200000,
        300000,
        400000,
        500000,
        600000,
        700000,
        800000,
        900000,
        1000000,
        1500000,
        2000000,
        2500000,
        5000000,
        10000000
    );
    $maximum_price_values = get_option('theme_maximum_price_values');
    if (!empty($maximum_price_values)) {
        $max_prices_string_array = explode(',', $maximum_price_values);
        if (is_array($max_prices_string_array) && !empty($max_prices_string_array)) {
            $new_max_prices_array = array();
            foreach ($max_prices_string_array as $string_price) {
                $integer_price = doubleval($string_price);
                if ($integer_price > 1) {
                    $new_max_prices_array[] = $integer_price;
                }
            }
            if (!empty($new_max_prices_array)) {
                $max_price_array = $new_max_prices_array;
            }
        }
    }
    $maximum_price = '';
    if (isset($_GET['max-price'])) {
        $maximum_price = doubleval($_GET['max-price']);
    }
    if (!empty($max_price_array)) {
        foreach ($max_price_array as $price) {
            if ($maximum_price == $price) {
                echo '<option value="' . $price . '" selected="selected">' . get_custom_price($price) . '</option>';
            } else {
                echo '<option value="' . $price . '">' . get_custom_price($price) . '</option>';
            }
        }
    }
    if ($maximum_price == 'any' || empty($maximum_price)) {
        echo '<option value="any" selected="selected">' . __('Any', 'framework') . '</option>';
    } else {
        echo '<option value="any">' . __('Any', 'framework') . '</option>';
    }
}

这是鳕鱼安迪让我找到,我希望这是一个:

        if( isset($_GET['min-price']) && ($_GET['min-price'] != 'any') && isset($_GET['max-price']) && ($_GET['max-price'] != 'any') ){
        $min_price = doubleval($_GET['min-price']);
        $max_price = doubleval($_GET['max-price']);
        if( $min_price >= 0 && $max_price > $min_price ){
            $meta_query[] = array(
                'key' => 'REAL_HOMES_property_price',
                'value' => array( $min_price, $max_price ),
                'type' => 'NUMERIC',
                'compare' => 'BETWEEN'
            );
        }
    }elseif( isset($_GET['min-price']) && ($_GET['min-price'] != 'any') ){
        $min_price = doubleval($_GET['min-price']);
        if( $min_price > 0 ){
            $meta_query[] = array(
                'key' => 'REAL_HOMES_property_price',
                'value' => $min_price,
                'type' => 'NUMERIC',
                'compare' => '>='
            );
        }
    }elseif( isset($_GET['max-price']) && ($_GET['max-price'] != 'any') ){
        $max_price = doubleval($_GET['max-price']);
        if( $max_price > 0 ){
            $meta_query[] = array(
                'key' => 'REAL_HOMES_property_price',
                'value' => $max_price,
                'type' => 'NUMERIC',
                'compare' => '<='
            );
        }
    }

    if( isset($_GET['min-area']) && !empty($_GET['min-area']) && isset($_GET['max-area']) && !empty($_GET['max-area']) ){
        $min_area = intval($_GET['min-area']);
        $max_area = intval($_GET['max-area']);
        if( $min_area >= 0 && $max_area > $min_area ){
            $meta_query[] = array(
                'key' => 'REAL_HOMES_property_size',
                'value' => array( $min_area, $max_area ),
                'type' => 'NUMERIC',
                'compare' => 'BETWEEN'
            );
        }
    }elseif( isset($_GET['min-area']) && !empty($_GET['min-area']) ){
        $min_area = intval($_GET['min-area']);
        if( $min_area > 0 ){
            $meta_query[] = array(
                'key' => 'REAL_HOMES_property_size',
                'value' => $min_area,
                'type' => 'NUMERIC',
                'compare' => '>='
            );
        }
    }elseif( isset($_GET['max-area']) && !empty($_GET['max-area']) ){
        $max_area = intval($_GET['max-area']);
        if( $max_area > 0 ){
            $meta_query[] = array(
                'key' => 'REAL_HOMES_property_size',
                'value' => $max_area,
                'type' => 'NUMERIC',
                'compare' => '<='
            );
        }
    }

这是我发现的另外两个代码,即渲染此下拉价格

    $('#select-min-price,#select-max-price').change(function(obj, e){
        var min_text_val = $('#select-min-price').val();
        var min_int_val = (isNaN(min_text_val))?0:parseInt(min_text_val);

        var max_text_val = $('#select-max-price').val();
        var max_int_val = (isNaN(max_text_val))?0:parseInt(max_text_val);

        if( (min_int_val >= max_int_val) && (min_int_val != 0) && (max_int_val != 0)){
            $('#select-max-price_input,#select-min-price_input').css('outline','2px solid red');
        }else{
            $('#select-max-price_input,#select-min-price_input').css('outline','none');
        }
    });


    $('#min-area,#max-area').change(function(obj, e){
        var min_text_val = $('#min-area').val();
        var min_int_val = (isNaN(min_text_val))?0:parseInt(min_text_val);

        var max_text_val = $('#max-area').val();
        var max_int_val = (isNaN(max_text_val))?0:parseInt(max_text_val);

        if( (min_int_val >= max_int_val) && (min_int_val != 0) && (max_int_val != 0)){
            $('#min-area,#max-area').css('outline','2px solid red');
        }else{
            $('#min-area,#max-area').css('outline','none');
        }
    });

我从WordPress主题中获得了这个名为Real Homes的代码,在我只能放1000的设置中,我试图将其设为1K,它从下拉列表选择列表中消失。

我是否必须更改整个代码,否则我必须更换它。

提前致谢

0 个答案:

没有答案