How to customised Osclass theme search bar

C

codeguru

Member
Freecoin
295
This tutorial will teach you how you can customised Osclass theme search bar by adding more query like search by city or region etc

Example of This code from oc-content\themes\modern\inc.search.php,

The search form code look like this:

<form action="<?php echo osc_base_url(true); ?>" method="get" class="search" onsubmit="javascript:return doSearch();"> <input type="hidden" name="page" value="search" /> <fieldset class="main"> <input type="text" name="sPattern" id="query" value="<?php echo osc_esc_html( ( osc_search_pattern() != '' ) ? osc_search_pattern() : $sQuery ); ?>" /> <?php if ( osc_count_categories() ) { ?> <?php osc_categories_select('sCategory', null, __('Select a category', 'modern')); ?> <?php } ?> <button type="submit"><?php _e('Search', 'modern'); ?></button> </fieldset> <div id="search-example"></div> </form>

Now I want to change or customised the following codes:


<input type="text" name="sCity" id="sCity" value="<?php _e('Enter your city here'); ?>" />

that's give the result like following,
View attachment 1

The solution:

action="<?php echo osc_base_url(true); ?>" method="get" class="search" onsubmit="javascript:return doSearch();">
<input type="hidden" name="page" value="search" />
<fieldset class="main">
<input type="text" name="sPattern" id="query" value="<?php echo osc_esc_html( ( osc_search_pattern() != '' ) ? osc_search_pattern() : $sQuery ); ?>" />
<input type="text" name="sCity" id="sCity" value="<?php _e('Enter your city here'); ?>" />
<?php if ( osc_count_categories() ) { ?>
<?php osc_categories_select('sCategory', null, __('Select a category', 'modern')); ?>
<?php } ?>
<button type="submit"><?php _e('Search', 'modern'); ?></button>
</fieldset>
<div id="search-example"></div>
</form>

Also, change sCity to sRegion if you prefer to seach by region and not by city.

For Selectable city field


?php $aCities = City::newInstance()->listAll(); ?>
<?php if(count($aCities) > 0 ) { ?>
<select name="sCity" id="sCity">
<option value=""><?php _e('Select a city...')?></option>
<?php foreach($aCities as $city) { ?>
<option value="<?php echo $city['s_name'] ; ?>"><?php echo $city['s_name'] ; ?></option>
<?php } ?>
</select>
<?php } ?>
 

Richest Freecoded User

Most Freecoin

freecoded
freecoded
2,577 Freecoin
Davy200
Davy200
590 Freecoin
nathan69
nathan69
424 Freecoin
Laureine
Laureine
415 Freecoin
C
codeguru
295 Freecoin
Tekera
Tekera
263 Freecoin
R
ruthailand
221 Freecoin
A
Akubay
170 Freecoin
smitha
smitha
104 Freecoin
G
Gabby
93 Freecoin
Top