You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何修改WordPress房产网站滑块代码,将默认最小值设置为0

Fixing the WordPress Property Slider to Start at €0

Got it, let's get that price slider initialized to €0 instead of defaulting to the cheapest property's price. Here's the straightforward fix for your code:

Step 1: Force the Minimum Value to 0

Your current code only sets $min to 0 when the minimum and maximum prices are equal. We need to override that and always set the minimum to 0, regardless of the property price range.

Replace this line:

<?php if( $min == $max ) $min = 0; ?>

With this line:

<?php $min = 0; ?>

Step 2: Updated Full Code

Here's the complete modified code snippet with the fix applied:

<?php $min = 0; // Force minimum slider value to 0 ?>
<?php if( $model ): ?>
<stm-field-range inline-template data-v-bind_key="generateRandomId()" data-v-model='<?php echo esc_attr( $model ); ?>' data-v-bind_callback_change='<?php echo esc_attr( $callback_change ); ?>' prefix='<?php echo esc_attr( $prefix ); ?>' suffix='<?php echo esc_attr( $suffix ); ?>' min='<?php echo esc_attr( $min ); ?>' max='<?php echo esc_attr( $max ); ?>'>
<div class="inventory-range-filter">
<div class="container">
<?php if( isset( $field[ 'label' ] ) ) { $field_range_before = apply_filters( "stm-field-range-before", [ 'model' => $model, 'prefix' => $prefix, 'field' => $field ] ); echo ( !is_array( $field_range_before ) ) ? $field_range_before : ""; } ?>
<div class="filter-range-fields">
<input type="text" data-v-model="from" data-v-on_change="setValue(from+';'+to)" data-v-on_keyup="setValue(from+';'+to)">
<input type="text" data-v-model="to" data-v-on_change="setValue(from+';'+to)" data-v-on_keyup="setValue(from+';'+to)">
</div>
<vue-range-slider data-v-bind_min="min" data-v-bind_max="max" data-v-bind_from="cloneFrom" data-v-bind_to="cloneTo" type="double" data-v-bind_prefix="prefix" data-v-bind_postfix="suffix" data-v-on_callback='updateValue' data-v-bind_key="generateRandomId()">
</vue-range-slider>
<?php if( isset( $field[ 'label' ] ) ) { $field_range_after = apply_filters( "stm-field-range-after", [ 'model' => $model, 'prefix' => $prefix, 'field' => $field ] ); echo ( !is_array( $field_range_after ) ) ? $field_range_after : ""; } ?>
</div>
</div>
</stm-field-range>
<?php endif; ?>

Why This Works

  • By setting $min = 0 unconditionally, we're telling the <stm-field-range> component that the slider's minimum allowed value is 0.
  • The Vue slider component (<vue-range-slider>) binds its min property to this $min value, and its initial from (left handle) position defaults to the min value. This ensures the slider starts at €0 instead of the cheapest property's price.

If you still see the old initial value after making this change, clear your staging site's cache (both WordPress and browser cache) to ensure the updated code loads properly.

内容的提问来源于stack exchange,提问作者Matt Partridge

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.29 12:02:35